
要创建一个粘性导航栏,请使用position: sticky;属性。您可以尝试运行以下代码来创建一个粘性导航栏,
实时演示
<!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>以上就是使用CSS创建一个固定的导航栏的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号