居中正文内容 HTML 和 CSS
Centering body content HTML and CSS
我无法将网页内容居中。目前在我的移动设备上看起来像这样:
我希望将此页面的所有内容在屏幕上居中并使宽度填满页面。
我的HTML如下:
<html>
<head>
<link rel="stylesheet" media="screen and (max-device-width: 799px)" type="text/css" href="stylesheet_small.css" />
<link rel="stylesheet" media="screen and (min-device-width: 800px)" type="text/css" href="stylesheet_large.css" />
<div class ="container_header">
<div class="header">
<div class="nav">
<a href="index.php" class="body">HOME</a>.....etc.
</div>
</div>
</div>
</head>
<body>
<p id="content">
<div class="container_top">
<div id="logo"><img border="0" src="images/introspect_logo_container.png" alt="INTROSPECT PICTURES" align="center"></div>
</div>
<div class ="container_body">
<br><div class ="current_page"><b>INTROSPECT</b> HOME</div>
<hr>
....
<div id="featured_pic"><img border="0" src="images/index_fliers.jpg" alt="FLIERS" align="center"></div>
</div>
</p>
</body>
<div class="footer">
....
</div>
</html>
stylesheet_small
的CSS如下所示:
body {
text-align: center;
}
.header {
width:auto;
text-align: center;
padding:10px;
border-radius: 5px;
}
.container_top {
text-align: center;
width:auto;
border-radius: 5px;
}
.container_body {
text-align: center;
width:auto;
padding:10px;
border-radius: 5px;
}
#logo {
width: auto;
}
#featured_pic {
width: auto;
}
我已将文本和图像居中对齐,并将每个 class 的宽度设置为 auto
。我还需要做什么?谢谢。
尝试添加
保证金:0 自动;
到你想要居中的 div
此外,您的导航栏 (container_header) 对于较小的视口来说太宽了,并且会使您的布局不正常。看看为较小的设备折叠导航栏以避免这种情况。
我无法将网页内容居中。目前在我的移动设备上看起来像这样:
我希望将此页面的所有内容在屏幕上居中并使宽度填满页面。
我的HTML如下:
<html>
<head>
<link rel="stylesheet" media="screen and (max-device-width: 799px)" type="text/css" href="stylesheet_small.css" />
<link rel="stylesheet" media="screen and (min-device-width: 800px)" type="text/css" href="stylesheet_large.css" />
<div class ="container_header">
<div class="header">
<div class="nav">
<a href="index.php" class="body">HOME</a>.....etc.
</div>
</div>
</div>
</head>
<body>
<p id="content">
<div class="container_top">
<div id="logo"><img border="0" src="images/introspect_logo_container.png" alt="INTROSPECT PICTURES" align="center"></div>
</div>
<div class ="container_body">
<br><div class ="current_page"><b>INTROSPECT</b> HOME</div>
<hr>
....
<div id="featured_pic"><img border="0" src="images/index_fliers.jpg" alt="FLIERS" align="center"></div>
</div>
</p>
</body>
<div class="footer">
....
</div>
</html>
stylesheet_small
的CSS如下所示:
body {
text-align: center;
}
.header {
width:auto;
text-align: center;
padding:10px;
border-radius: 5px;
}
.container_top {
text-align: center;
width:auto;
border-radius: 5px;
}
.container_body {
text-align: center;
width:auto;
padding:10px;
border-radius: 5px;
}
#logo {
width: auto;
}
#featured_pic {
width: auto;
}
我已将文本和图像居中对齐,并将每个 class 的宽度设置为 auto
。我还需要做什么?谢谢。
尝试添加
保证金:0 自动;
到你想要居中的 div
此外,您的导航栏 (container_header) 对于较小的视口来说太宽了,并且会使您的布局不正常。看看为较小的设备折叠导航栏以避免这种情况。