相对div在滚动时经过固定div

Mto*_*tok 8 css

我在页面顶部有一个固定的div.(例如Facebook)和页面中相对定位的div.当我向下滚动时,相对div通过固定div.我想让它通过固定的div.有没有想法处理这个?

在此输入图像描述

#navcontainer
{
    position:fixed;
}

.city
{
    position:relative;
    float:left; 
}

.city .text 
{
    position:absolute;
    top:100px; 
    left:15px;
}
Run Code Online (Sandbox Code Playgroud)

在这个CSS我有一个城市div和绝对文本坐在相对div(.city)的图像上

Roh*_*zad 14

嗨,我认为你应该这样做:

CSS

#navcontainer
{
    position:fixed;
    background:red;
    left:0;
    right:0;
    top:0;
    height:100px;
    z-index:3;
}

.city
{
    position:relative; 
    background:green;
    left:0;
    right:0;
    padding:10px;
    top:100px;
    z-index:2;
}

.city .text 
{
    padding:10px;
    background:yellow;
}?
Run Code Online (Sandbox Code Playgroud)

HTML

<div id="navcontainer">This is navigation</div>

<div class="city">
    <div class="text">here text <br />here text <br />here text <br />here text <br />here text <br />here text <br />here text <br />here text <br />here text <br />here text <br />here text <br />here text <br />here text <br />here text <br />here text <br />here text <br />here text <br />here text <br />here text <br />here text <br />here text <br />here text <br />here text <br />here text <br />here text <br />here text <br />here text <br />here text <br />here text <br />here text <br />here text <br />here text <br />here text <br />here text <br />here text <br />here text <br />here text <br />here text <br />here text <br />here text <br />here text <br />here text <br />here text <br />here text <br />here text <br />here text <br />here text <br />here text <br /></div>
</div>
?
Run Code Online (Sandbox Code Playgroud)

现场演示http://jsfiddle.net/xLnKN/1/


Rus*_*sak 5

我认为您正在寻找的是 CSS 属性z-index。有关文档,请参见此处:http : //reference.sitepoint.com/css/z-index

我拼凑了一个小例子,展示了如何在你的 CSS 中使用它:http : //jsfiddle.net/B63Km/

基本思想是 z-index 越高,元素离你越近。