CSS 布局固定宽度
我的目标是固定宽度布局,在所有显示器上使用 width:1008px
。这是我的 HTML
<body>
<div id="god_container">
<div id="root">
... all content ...
</div>
</div>
</body>
和 CSS -
#god_container{
background:url("/site_media/images/bg-1008.png") repeat-y scroll center center #D4D9DD;
margin:auto;
position:static;
width:auto;
}
#root {
background-color:#FFFFFF;
margin:auto;
width:1008px;
color:#000000;
font-family:Verdana,Arial,sans-serif;
font-size:10pt;
}
body{
color:#373737;
font:16px arial;
line-height:1;
background-color:#D4D9DD;
}
我认为这可以解决这个问题。但是当我渲染时,root
css 不遵守 1008px
值。此外,root 的 background-color
不会显示为 #FFFFFF
即白色。它仍然显示我的body
的background-color
。我做错了什么?
更新:对于任何感兴趣的人,我在 http: //www.dynamicdrive.com/style/layouts/category/C12/
I am aiming for a fixed width layout, with width:1008px
across all monitors. Here's my HTML-
<body>
<div id="god_container">
<div id="root">
... all content ...
</div>
</div>
</body>
and CSS -
#god_container{
background:url("/site_media/images/bg-1008.png") repeat-y scroll center center #D4D9DD;
margin:auto;
position:static;
width:auto;
}
#root {
background-color:#FFFFFF;
margin:auto;
width:1008px;
color:#000000;
font-family:Verdana,Arial,sans-serif;
font-size:10pt;
}
body{
color:#373737;
font:16px arial;
line-height:1;
background-color:#D4D9DD;
}
I thought this would solve it. But when I render, the root
css does not adhere to 1008px
value. Also root's background-color
does not show as #FFFFFF
i.e. White. It still shows my body
's background-color
. What am I doing wrong?
UPDATE: To anyone interested I have found excellent ready-made CSS layouts at http://www.dynamicdrive.com/style/layouts/category/C12/
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
为正文提供
背景图像
和颜色,确保它显示在所有页面上,并让#god_container
充当页面的包装器,将其居中margin:0 auto;
并为其指定width:1008px;
。另外,您不必将
position:static;
提供给#god_container
包装 div,而是使用position:relative;
来确保即使绝对定位,所有子 div 也会放置在其中。最后,给
#root
一个width:100%
会将 div 放置到它的父 div 宽度。尝试使用这个CSS:
Giving the
background-image
and color to the body, makes sure it is displayed on all pages, and have the#god_container
act as a wrapper for the page, center it bymargin:0 auto;
and give it thewidth:1008px;
.Also you don't have to give the
position:static;
to the#god_container
wrapping div, instead useposition:relative;
to make sure all child divs, are placed inside it even if positioned absolutely.At last, giving
#root
awidth:100%
will place the div to it's parent div width.Try using this CSS:
不确定我是否在这里遗漏了一些东西,但它可以更简单。您不需要包装 DIV...主体可以处理它。您所需要的只是您的根 DIV。
CSS
HTML
在这里:http://jsfiddle.网/XdA92/1/
Not sure if I'm missing something here, but it could be much simpler. You don't need a wrapper DIV... the body can handle that. All you need is your root DIV.
CSS
HTML
Here ya go: http://jsfiddle.net/XdA92/1/
尝试下面的方法。
将后台 url 提供给主体,以便它可以转到所有页面
Try the below.
give the back ground url to the main body so that it will go to all pages