[英]How to add horizontal scrollbar when container and children have width auto?
My container has the following styling: 我的容器具有以下样式:
.timeFrameContainer {
height: 140px;
padding-top: 10px;
overflow-y: hidden;
overflow-x: scroll;
width:auto;
}
and the children inside: 里面的孩子们:
.nutrient {
width: auto;
height: 120px;
margin-left: 10px;
margin-right: 10px;
display: inline-block;
}
All my containers show up next to eachother untill the full width of the page has been reached. 我所有的容器都紧挨着出现,直到达到页面的整个宽度为止。 After this the children show up underneath the others. 之后,孩子们出现在其他人的下面。
I want them all to show up next to eachother and show a horizontal scrollbar whenever it exceeds the page width. 我希望它们全部显示在彼此的旁边,并且每当超过页面宽度时显示一个水平滚动条。 How do I do this? 我该怎么做呢?
To prevent the wrapping of inline elements, assign white-space: nowrap
to the container: 为了防止内联元素的换行,请将white-space: nowrap
分配给容器:
.timeFrameContainer { height: 140px; padding-top: 10px; overflow-y: hidden; overflow-x: scroll; width:auto; white-space: nowrap; } .nutrient { width: 120px; /** changed for the demo **/ height: 120px; margin-left: 10px; margin-right: 10px; display: inline-block; background: red; /** changed for the demo **/ }
<div class="timeFrameContainer"> <div class="nutrient"></div> <div class="nutrient"></div> <div class="nutrient"></div> <div class="nutrient"></div> <div class="nutrient"></div> <div class="nutrient"></div> <div class="nutrient"></div> <div class="nutrient"></div> </div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.