CSS3 - 粘滞的位置不起作用

时间:2016-03-28 08:18:30

标签: html css3

我尝试使用粘性定位在标题部分下创建导航菜单,但我无法使其正常工作,这里是我的css代码:

    body{

}
header{
    position: relative;
    top: 0px;
    left: 0px;
    height: 100px;
    width: 100%;
    background-color: whitesmoke;
    text-align: left;
    float: left;
    padding: 5px;
    z-index:100;
}
    #logo{
        position: relative;
        height: 85px;
        width: 120px;
        /*border: 1px solid black;*/
        float: left;
        background-image: url('logoArdi.svg');
        background-position: center;
        background-size: contain;
    }
    #judulWeb{
        position: relative;
        height: 85px;
        width: 200px;

        text-align: center;
        float: left;
    }
    #kontak{
        position: inherit;
        float: right;
        height: 100px;
        top: 20px;
        right: 10px;
    }
        .imghead{
            margin: auto 5px auto auto;
        }
    .sticky{
        position: sticky;
        position: -webkit-sticky;
        position: -o-sticky;
        top: 0px;
        float: left;
        width: 100%;
        height:30px;
        background-color: #26282b;
        text-align: center;
        box-shadow: 0px 2px 10px #26282b;
    }

        ul li{
            position:relative;
            bottom:11px;
            display: inline-block;
            margin: auto 30px auto auto;
        }
        ul li{
            color:whitesmoke;

            /*background-color:black;
            border-radius: 5px 5px 0px 0px;
            padding: 5px;*/
        }
        ul li:hover{
            color:#26282b;
            background-color: whitesmoke ;
        }
    #kontak{
        position: inherit;
        float: right;
        height: 100px;
    }
#wrapper{
    position: relative;
    top: 132px;
    width: 80%;
    float: left;
    margin-right: 10%;
    margin-left: 10%;
    text-align: center;
    background-color: transparent;
}
    .imgutama{
        width: 200px;
    }

我现在不知道错误,但我打算创建页面标题和导航,导航位于页面标题下方,即使我向下滚动也会保持在顶部。

注意:导航类是"粘性"。

1 个答案:

答案 0 :(得分:-1)

#sidebar {
    position: -webkit-sticky;  // required for Safari
    position: sticky;
    top: 0; // required as well.
}