使用CSS创建粘性导航栏
要创建粘性导航栏,请使用以下位置:属性。您可以尝试运行以下代码来创建粘性导航栏,
示例
<!DOCTYPE html>
<html>
<head>
<style>
ul {
list-style-type: none;
position: sticky;
overflow: hidden;
top: 0;
width: 100%;
}
li {
float: left;
border-right: 1px solid white;
}
li a {
display: block;
padding: 8px;
background-color: orange;
}
li:last-child {
border-right: none;
}
div {
padding:5px;
margin-top:5px;
background-color:white;
height:1000px;
}
</style>
</head>
<body>
<ul>
<li><a href = "#home">Home</a></li>
<li><a href = "#news">News</a></li>
<li><a href = "#contact">Contact</a></li>
<li><a href = "#about">About</a></li>
</ul>
<div>
<p>Adding demo text to check fixed menu.</p>
<p>Adding demo text to check fixed menu.</p>
<p>Adding demo text to check fixed menu.</p>
<p>Adding demo text to check fixed menu.</p>
<p>Adding demo text to check fixed menu.</p>
<p>Adding demo text to check fixed menu.</p>
<p>Adding demo text to check fixed menu.</p>
<p>Adding demo text to check fixed menu.</p>
<p>Adding demo text to check fixed menu.</p>
<p>Adding demo text to check fixed menu.</p>
<p>Adding demo text to check fixed menu.</p>
<p>Adding demo text to check fixed menu.</p>
<p>Adding demo text to check fixed menu.</p>
<p>Adding demo text to check fixed menu.</p>
</div>
</body>
</html>热门推荐
10 新年祝福语长篇文案简短
11 家长祝福语大全简短内容
12 新婚过年祝福语大全简短
13 宝宝周岁敬酒祝福语简短
14 孙女结婚姥姥祝福语简短
15 过节文案成语祝福语简短
16 理科元旦祝福语大全简短
17 俄语祝福语贺卡文案简短
18 永远漂亮祝福语女生简短