【发布时间】:2011-11-02 21:49:10
【问题描述】:
我在一个页面上有两个 div。一个网格容器,它采用背景和需要定位在另一个网格中心的内部网格。我的CSS:
html, body{
margin:0;
padding:0;
width:100%;
}
#grid-container{
background:#f8f8f8 url(../images/grid-container-bg.gif) repeat-x top left;
width:100%;
}
#grid{
width:1140px;
margin:0px auto;
}
此时,#grid-container 的 bg 图片只填满了窗口,而不是 html 的全宽。其症状是,如果您缩小浏览器窗口以便需要水平滚动条并刷新页面,则 bg 图像会在浏览器窗口结束的位置结束。当我向右滚动时,bg 图像不存在。想法?
编辑:好的,根据请求,我已经编辑了我的 css/html。当我删除#grid-container 中的宽度指定时,它会缩小到容器内的宽度,这更糟。这是我现在拥有的:
html, body{
margin:0;
padding:0;
min-width:1140px;
}
body{
background:url(../images/page-background.jpg) repeat-x top left !important;
height:100%;
}
#grid-container{
background:#f8f8f8 url(../images/grid-container-bg.gif) repeat-x top left;
padding-top:1px;
}
#grid-container2{
width:1140px;
margin:0px auto;
}
.clearfix:after {
content: ".";
display: block;
clear: both;
visibility: hidden;
line-height: 0;
height: 0;
}
.clearfix {
display: inline-block;
}
html[xmlns] .clearfix {
display: block;
}
* html .clearfix {
height: 1%;
}
和html:
<!DOCTYPE HTML>
<html>
<head>
---
</head>
<body>
...
<div id="grid-container" class="clearfix">
<div id="grid">..all kinds of things in here</div>
</div>
【问题讨论】:
-
你能添加你的HTML吗?
-
这是合乎逻辑的。您告诉浏览器将宽度设置为浏览器的 100%。
-
删除 width:100% 就可以了。 impressivewebs.com/width-100-percent-css