新出的定位方式,兼容性不是很好
粘滞定位就是说它在某些范围内是可以动,但是到了某些条件,它就固定了
<!DOCTYPE html>
<html lang="ch">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>粘滞定位</title>
<style>
body {
height: 8888px;
}
.nav {
width: 1210px;
height: 48px;
margin: 400px auto;
background-color: rgb(232, 231, 227);
line-height: 48px;
position: sticky;
top: 50px;
/*
粘滞定位
- position开启了sticky,就开启了粘滞定位
- 粘滞定位的特点跟相对定位的特点基本一致,
不同的是粘滞定位可以在元素到达某个位置时将其固定
*/
}
.nav li {
list-style: none;
float: left;
text-align: center;
}
.nav li a {
display: inline-block;
height: 100%;
width: 100%;
color: rgb(119, 119, 119);
text-decoration: none;
font-size: 16px;
}
.nav ul {
margin: 0;
padding: 0;
}
#h {
width: 166px;
}
#b {
width: 191px;
}
#s {
width: 175px;
}
#p {
width: 198px;
}
#x {
width: 113px;
}
#w {
width: 197px;
}
#r {
width: 170px;
}
.nav a:hover {
background-color: rgb(63,63,63);
color: rgb(232,231,227);
}
</style>
</head>
<body>
<div class="nav">
<ul>
<li id="h"><a href="#">HTML/CSS</a></li>
<li id="b"><a href="#">Browser Side</a></li>
<li id="s"><a href="#">Sever Side</a></li>
<li id="p"><a href="#">Programming</a></li>
<li id="x"><a href="#">XML</a></li>
<li id="w"><a href="#">Web Building</a></li>
<li id="r"><a href="#">Reference</a></li>
</ul>
</div>
</body>
</html>