Css Div包装器未将所有页面内容居中
是什么原因导致以下内容无法使整个页面居中Css Div包装器未将所有页面内容居中,css,html,Css,Html,是什么原因导致以下内容无法使整个页面居中 <html> <style type="text/css"> .col { width: 250px; float: left } </style> <body> <div style="width=500px;margin:0 auto;"> <p style="float:left;t
<html>
<style type="text/css">
.col {
width: 250px;
float: left
}
</style>
<body>
<div style="width=500px;margin:0 auto;">
<p style="float:left;text-align:right;width:120px;line-height: 26px;">
</p>
<p style="float:left;width:150px;margin-left:20px;">
</p>
<div style="clear:both;"></div>
<div class="col">
<p>
</p>
</div>
<div class="col">
<p>
</p>
</div>
</div>
</body>
</html>
上校{
宽度:250px;
浮动:左
}
它应该是宽度:500px
而不是宽度=500px
您使用的是内联样式,这是一种糟糕的做法
写下:
.wrapper{width:500px;margin:0 auto;background:#eee;}
我认为其中一个原因是,您的
div大部分都是浮动的。如果您浮动所有内容,然后使用margin:0 auto代码>由于float属性,它将无效。您是否正在尝试制作特定的列布局(2或3)
尝试使用div创建列,并将它们与float属性适当对齐,甚至完全丢失包装器div,并使用:html{text align:center;}body{background:#eee;margin:0 auto;width:500px;}居中