【发布时间】:2013-10-11 00:12:12
【问题描述】:
绝对定位(侧面黄色广告)的 div 在调整窗口大小(尺寸减小)超出它们时会导致不需要的水平滚动条。只有当 window 小于 main #container 时才会出现滚动条,并且这些广告 div 不应该影响布局。他们是否被覆盖并不重要。
HTML:
<div id='topbar'>
<div id='menu'> <a href='#'>Link1</a>
<a href='#'>Link2</a>
<a href='#'>Link3</a>
<a href='#'>Link4</a>
</div>
</div>
<div id='container'>
<div id='pushfix'></div>
<div id='ad_container'>
<div id='ad1'>ad</div>
<div id='ad2'>ad</div>
</div>
Lorem ipsum placeholder text
</div>
CSS:
body, html {
height:100%;
}
body {
margin:0;
}
#topbar {
width:100%;
background-color:#DCDCDC;
height:40px;
position:absolute;
}
#menu {
width:250px;
background-color:#B3B3B3;
margin:0 auto;
height:100%;
text-align:center;
line-height:40px;
}
#menu a {
color:#fff;
}
#container {
height:100%;
background-color:#808080;
width:240px;
padding:0 5px;
margin:0 auto;
}
#pushfix {
height:40px;
}
#ad_container {
position:relative;
width:240px;
}
#ad_container div {
width:100px;
background-color:yellow;
height:300px;
position:absolute;
}
#ad1 {
left:-105px;
}
#ad2 {
right:-105px;
}
精确布局副本:http://jsfiddle.net/8UkQA/
【问题讨论】:
-
为什么没有将你的 CSS 中的溢出设置为隐藏? w3schools.com/cssref/pr_pos_overflow.asp
-
在
body元素上设置overflow: hidden将阻止用户滚动到超出浏览器窗口高度的正文内容。