display:grid
on the container can do it
.item {
white-space: nowrap;
}
.item:hover {
background-color: #DDDDDD;
}
.container {
max-width: 200px;
overflow: auto;
display:grid;
}
<div class="container">
<div class="item">somewhat short item 1</div>
<div class="item">somewhat short item 2</div>
<div class="item">somewhat short item 3</div>
<div class="item">very long item that makes the container scroll</div>
<div class="item">somewhat short item 4</div>
<div class="item">somewhat short item 5</div>
<div class="item">somewhat short item 6</div>
<div class="item">somewhat short item 7</div>
</div>
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…