相对它的最近滚动祖先和最近块级祖先基于top
, right
, bottom
, 和 left
的值进行偏移
<!DOCTYPE html>
<html lang="en">
<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>Document</title>
<style>
.wrapper {
width: 200px;
height: 400px;
border: 1px solid coral;
overflow: scroll;
}
.item {
width: 180px;
margin: 10px;
border: 1px dotted cornflowerblue;
text-align: center;
line-height: 40px;
height: 40px;
}
.item:nth-child(3n + 1) {
position: sticky;
top: 0;
background-color: crimson;
}
</style>
</head>
<body>
<div class="wrapper">
<div class="item">1</div>
<div class="item">2</div>
<div class="item">3</div>
<div class="item">4</div>
<div class="item">5</div>
<div class="item">6</div>
<div class="item">7</div>
<div class="item">8</div>
<div class="item">9</div>
<div class="item">10</div>
<div class="item">11</div>
<div class="item">12</div>
<div class="item">13</div>
<div class="item">14</div>
</div>
</body>
</html>
网友评论