[英]CSS overflow and white-space not working
Using the following code I show a couple of divs floated to the left. 使用以下代码,我显示了几个div浮动到左侧。
* { margin: 0; padding: 0; border: none; box-sizing: border-box; } .container { width: 100%; height: 100%; } .header { height: 80px; position: fixed; width: 100%; background: green; } .inner-container { position: absolute; top: 80px; left: 0px; right: 0px; bottom: 0px; overflow: auto; white-space: nowrap; } .column { height: 500px; width: 150px; background: red; float: left; margin: 5px; }
<div class="container"> <div class="header"> </div> <div class="inner-container"> <div class="column"> </div> <div class="column"> </div> <div class="column"> </div> </div> </div>
Current result: 当前结果:
What I want is that the red boxes don't wrap within its container. 我想要的是红色框不包装在其容器中。 I want both, a vertical and horizontal scroll bar if the space is not enough. 如果空间不足,我需要垂直和水平滚动条。 For the vertical scrollbar it works. 对于垂直滚动条,它可以工作。 What am I missing? 我想念什么?
JSFiddle: https://jsfiddle.net/brainchest/j6zh400v/ JSFiddle: https ://jsfiddle.net/brainchest/j6zh400v/
A fix I found was to change the .column
from being a float: left
to display: inline-block
. 我发现的一个解决方法是将.column
从float: left
更改为display: inline-block
。 This treats each column as a "word" (like a word in text) and thus the white-space: no-wrap;
这会将每一列视为一个“单词”(就像文本中的单词一样),因此将其视为white-space: no-wrap;
applies. 适用。 Otherwise, the float: left
changes the way the element gets positioned. 否则, float: left
更改元素的定位方式。
Edited Fiddle: https://jsfiddle.net/9bo4f5pv/ 编辑的小提琴: https : //jsfiddle.net/9bo4f5pv/
Use display: flex
on the parent, then flex: 0 0 150px
on the columns. 在父级上使用display: flex
,然后在列上使用flex: 0 0 150px
。
* { margin: 0; padding: 0; border: none; box-sizing: border-box; } .container { width: 100%; height: 100%; } .header { height: 80px; position: fixed; width: 100%; background: green; } .inner-container { position: absolute; top: 80px; left: 0px; right: 0px; bottom: 0px; overflow: auto; display: flex; } .column { height: 500px; flex: 0 0 150px; background: red; margin: 5px; }
<div class="container"> <div class="header"> </div> <div class="inner-container"> <div class="column"> </div> <div class="column"> </div> <div class="column"> </div> </div> </div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.