gpt4 book ai didi

html - CSS3 - 粘性位置不起作用

转载 作者:行者123 更新时间:2023-11-28 15:20:12 25 4
gpt4 key购买 nike

我尝试在带有 sticky 定位的标题部分下创建导航菜单,但我无法让它工作,这是我的 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;
}

我现在没有弄错,但我只是想创建页眉和导航,导航位于页眉下方,即使我向下滚动也会保持在顶部。

注意:导航类是“粘性”的。

最佳答案

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

关于html - CSS3 - 粘性位置不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36258525/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com