Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/33.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/82.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 padding“;“除z像素外的所有像素”;_Css_Html_Centering - Fatal编程技术网

CSS-Div padding“;“除z像素外的所有像素”;

CSS-Div padding“;“除z像素外的所有像素”;,css,html,centering,Css,Html,Centering,我有一个div,它需要在整个页面上伸展,但是实际的内容应该只有z像素宽,并且居中。也就是说,文本不居中,但内容所在的区域(如果愿意的话,div的内部)居中 合乎逻辑的方法是这样做: <div> <!--I stretch across the entire page!--> <div> <!--I am z pixels wide, and my margins are auto. Content goes here.--> </div

我有一个div,它需要在整个页面上伸展,但是实际的内容应该只有z像素宽,并且居中。也就是说,文本不居中,但内容所在的区域(如果愿意的话,div的内部)居中

合乎逻辑的方法是这样做:

<div>
<!--I stretch across the entire page!-->
 <div>
 <!--I am z pixels wide, and my margins are auto. Content goes here.-->
 </div>
</div>

唯一的问题是,它似乎真的是div-itis-y。这应该可以通过使用box模型来实现


在不添加div的情况下,是否仍然可以这样做?

body
已经扩展了页面的宽度,因此只需使用一个内部
div

差不多

<body>
    <div></div>
</body>
这就是
div
s要做的事情

现在,根据内容以及是否使用HTML5,您可能希望将其全部包装在另一个元素标记中,例如
标题
导航
部分


但是使用
div
s本身并没有什么问题,即使是嵌套的也一样。

谢谢。不幸的是,我需要外部div是一条横跨整个页面的色带。我也同意-使用div没有本质上的错误-维护一个具有更少、更具逻辑性div的页面更容易。这是真的@guywhowneedsahand
div{
    width:980px;
    margin:0 auto;
}