粘制定位
<!DOCTYPE html>
<html lang="ch">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>导航条</title>
<link rel="stylesheet" href="/layout/css/reset.css">
<style>
body{
height: 3000px;
}
.nav{
width: 1210px;
height: 48px;
background-color: #E8E7E3;
margin: 100px auto;
position: sticky;
top: 0;
}
.nav li{
float: left;
line-height: 48px;
}
.nav a{
display: block;
padding: 0 39px;
text-decoration: none;
color: #777777;
font-size: 18px;
}
.nav li:last-child a{
padding: 0 46px 0 45px;
}
.nav a:hover{
background-color: #3f3f3f;
color: #E8E7E3;
}
</style>
</head>
<body>
<ul class="nav">
<li>
<a href="#">HTML/CSS</a>
</li>
<li>
<a href="#">Brower Side</a>
</li>
<li>
<a href="#">Server Side</a>
</li>
<li>
<a href="#">Programming</a>
</li>
<li>
<a href="#">XML</a>
</li>
<li>
<a href="#">Web Building</a>
</li>
<li>
<a href="#">Reference</a>
</li>
</ul>
</body>
</html>
- 粘制定位
-当元素的position属性设置为sticky时则开启元素的粘制定位
-粘制定位和相对定位的特点基本一致,
不同的是粘制定位可以在元素到达某个位置时将其固定