【发布时间】:2016-05-30 12:23:51
【问题描述】:
我的想法是在 3 个 div 下方并排放置一个横幅,我想做的是,当我向下滚动时,只有中心和右侧 div 移动。
#banner {
background:blue;
color:white;
position: fixed;
height:300px;
width:500px;
border-style: dotted;
}
#left {
background:blue;
color:white;
position: fixed;
top:300px;
height:300px;
width:150px;
border-style: dotted;
float:left;
}
#center {
background:red;
color:white;
top:300px;
left:150px;
height:700px;
width:150px;
border-style: dotted;
float:left;
z-index:-1;
}
#right {
background:red;
color:white;
top:300px;
left:300px;
height:300px;
width:150px;
border-style: dotted;
float:left;
z-index:-1;
}
<div id="banner">
banner
</div>
<div id="left">
left
</div>
<div id="center">
center
</div>
<div id="right">
right
</div>
据我了解,我应该在左侧和横幅 div 上使用 position: absolute 或 fixed。如果我这样做,我必须提供所有 DIV left: 和 top: 属性,并使它们组合在一起。我还应该给他们高度:和宽度和z-index到#center和#right。我担心这将无法在不同的浏览器、分辨率等中正确显示。有没有更简单的方法呢?
这是我失败的尝试:https://jsfiddle.net/y71fqthf/1/
如您所见,可以看到这些框位于其顶部的横幅下方。这是我不想要的。
或者这通常是显示网站的一种不好的方式?
【问题讨论】:
-
我会在内容 DIV 中添加一个容器,并在左侧和顶部添加一个
relative空白 DIV,以避免使用 LEFT 和 TOP 属性.. -
但是我给你的建议是使用一些网格,比如Bootstrap 这会让你更容易让网站响应
-
@miguelmpn 我正在使用引导程序,它的工作几乎完美。由于某种原因,在我的 iPhone 中它并没有填满整个屏幕。如果您想作为答案发布,请使用引导程序,您将获得学分。