【发布时间】:2014-01-21 15:57:03
【问题描述】:
我有一个有两行背景的页面。 一条线是黄色的,高度:65%,另一条线是灰色的,高度:35% 我在中心有一个绝对定位的 div,宽度和高度固定。 灰线就在我的 div 下方。问题是,当我更改页面大小或缩小(模拟大尺寸屏幕)时,我的 div 出现在灰色背景之上。如果我将每条背景线的高度设置为 50%,一切都很好,但我需要 65% 和 35%。 这是 jsfiddle 链接:http://jsfiddle.net/J2LTR/ 尝试缩小页面,黑色方块将超出灰色背景。 任何想法如何解决这个问题?
这是我的代码:
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style type="text/css">
html, body {
padding: 0;
margin: 0;
height: 100%;
min-height: 100%
}
.yellow {
width: 100%;
height: 65%;
background: #e5bd00;
background-repeat: repeat;
}
.gray {
width: 100%;
height: 35%;
background: #d2d2d2;
background-repeat: repeat;
}
.wrap {
min-width: 300px;
width: 100%;
height: 100%;
min-height: 600px;
margin: 0 auto;
position: relative;
}
.center_box {
background: #000;
position: absolute;
top: 50%;
left: 50%;
margin-top: -120px;
margin-left: -200px;
width: 400px;
height: 235px;
}
</style>
</head>
<body>
<div class="wrap">
<div class="yellow"></div>
<div class="gray"></div>
<div class="center_box">some content</div>
</div>
</body>
</html>
【问题讨论】:
标签: html css background liquid-layout