以下代码有什么问题?所需的行为是#library {
position: absolute;
bottom: 0; left: 0; right: 0;
height: 60px;
overflow-x: scroll;
overflow-y: hidden;
}
body { overflow: hidden; }
.item {
display: inline-block;
width: 50px; height: 50px;
margin: 5px;
border: 1px solid gray;
}
元素跨越“屏幕”的底部并水平滚动。
<div id="library">
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
</div>
inp1
答案 0 :(得分:3)
.item
元素在到达#library
的末尾时换行。由于overflow-y: hidden
,您无法看到多行包装元素。将white-space: nowrap;
添加到#library
以防止包装物品。
#library {
position: absolute;
bottom: 0;
left: 0;
right: 0;
height: 60px;
overflow: scroll;
overflow-y: hidden;
white-space: nowrap;
}
body {
overflow: hidden;
}
.item {
display: inline-block;
width: 50px;
height: 50px;
margin: 5px;
border: 1px solid gray;
}
<div id="library">
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
</div>