这是粘性元素的一个简单示例,但我想知道为什么我不能为粘性元素(绿色块)设置高度。
.container {
background: red;
display: flex;
flex-direction: column;
height: 30vh;
width: 150px;
overflow: auto;
/* position: fixed; */
}
.btn {
background: green;
position: sticky;
height: 50px; /* why does not work?!! */
bottom: 0;
left: 0;
right: 0;
}
<div class='container'>
<div class='items'>
<div>hello world </div>
<div>hello world </div>
<div>hello world </div>
<div>hello world </div>
<div>hello world </div>
<div>hello world </div>
<div>hello world </div>
<div>hello world </div>
<div>hello world </div>
<div>hello world </div>
<div>hello world </div>
<div>hello world </div>
</div>
<button class='btn'>+</button>
</div>
我删除了
position: fixed
但仍然不起作用!