我正在處理一些基本的網頁佈局。問題是,瀏覽器不會忽略從包裝中溢出的元素,並且如果屏幕比1050像素更接近(1050像素是包裝寬度),則添加horzinotal滾動條。看看代碼:強制瀏覽器忽略來自包裝器的溢出元素
HTML
<body>
<div id="wrapperMain">
<div id="headerLeftOverflow"></div>
<div id="headerRightOverflow"></div>
<div id="headerMain"></div>
</div>
</body>
CSS
body {
margin: 0;
padding: 0;
background-color: #f9eacc;
text-align: center;
font-family: Tahoma , sans-serif;
color: #333333;
}
div#wrapperMain {
width: 1050px;
margin: auto;
position: relative;
height: 800px;
}
div#headerMain {
position: absolute;
top: 0;
left: 0;
width: 1050px;
height: 565px;
background-image: url("../images/header.png");
background-repeat: no-repeat;
}
div#headerLeftOverflow {
position: absolute;
width: 271px;
height: 565px;
background-image: url("../images/headerLeftOverflow.png");
top: 0;
left: -271px;
}
div#headerRightOverflow {
position: absolute;
width: 277px;
height: 565px;
background-image: url("../images/headerRightOverflow.png");
top: 0;
left: 1050px;
}
不要誤會我的意思。
如果屏幕寬度很寬,我想讓id爲「headerRightOverflow」的div可見。奇怪的是,ID爲「headerLeftOverflow」的div可以正常工作(如果屏幕比1050 px更近,div被隱藏)。
如果我說得對。當屏幕寬度超過1050像素時,需要div出現? – Katti