grid-template-rows
每当您将鼠标悬停在具有overflow
并将位置auto height
移动scroll
到溢出容器底部的任何元素上时(body
在这种情况下),这是预期的行为吗?
最明显的滚动中断效果是当您在 2 个li
元素之间做圆圈并尝试在片段 #1 上向上或向下滚动时。
当我移除:hover
滚动条时li
不会中断。
.container{
display: grid;
grid-template-rows: 10vh auto 8vh;
width: 400px;
height: 300px;
background: rgba(0,0,0.2);
}
.header{
background: lightblue;
}
.body{
background: white;
overflow: auto;
}
.footer{
background: lightgreen;
}
li{
height: 30px;
background: rgba(0,0,0,.5);
opacity: 1;
}
li:nth-child(even){
background: rgba(0,0,0,.2);
}
li:hover{
opacity: .1;
}
<div class="container">
<div class="header">header</div>
<div class="body">body
<ul>
<li>foo</li>
<li>foo</li>
<li>foo</li>
<li>foo</li>
<li>foo</li>
<li>foo</li>
<li>foo</li>
<li>foo</li>
<li>foo</li>
<li>foo</li>
<li>foo</li>
<li>foo</li>
<li>foo</li>
<li>foo</li>
<li>foo</li>
<li>foo</li>
<li>foo</li>
<li>foo</li>
<li>foo</li>
<li>foo</li>
<li>foo</li>
</ul>
</div>
<div class="footer">footer</div>
</div>
另一方面,如果您将中间值硬编码为 ie40vh
而不是auto
scroll 按预期工作。
.container{
display: grid;
grid-template-rows: 10vh 40vh 8vh;
width: 400px;
height: 300px;
background: rgba(0,0,0.2);
}
.header{
background: lightblue;
}
.body{
background: white;
overflow: auto;
}
.footer{
background: lightgreen;
}
li{
height: 30px;
background: rgba(0,0,0,.5);
opacity: 1;
}
li:nth-child(even){
background: rgba(0,0,0,.2);
}
li:hover{
opacity: .1;
}
<div class="container">
<div class="header">header</div>
<div class="body">body
<ul>
<li>foo</li>
<li>foo</li>
<li>foo</li>
<li>foo</li>
<li>foo</li>
<li>foo</li>
<li>foo</li>
<li>foo</li>
<li>foo</li>
<li>foo</li>
<li>foo</li>
<li>foo</li>
<li>foo</li>
<li>foo</li>
<li>foo</li>
<li>foo</li>
<li>foo</li>
<li>foo</li>
<li>foo</li>
<li>foo</li>
<li>foo</li>
</ul>
</div>
<div class="footer">footer</div>
</div>