Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Css Div包装器未将所有页面内容居中_Css_Html - Fatal编程技术网

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;}居中