使内联块水平拉伸容器
Make inline-blocks stretch container horizontally
我想这样做,如果容器内的内联块超过容器的宽度,它们会拉伸而不是下降到下方。
我把我的意思写成代码笔:http://codepen.io/anon/pen/pJQWbR
<div class="container">
<div class="content"></div>
<div class="content"></div>
<div class="content"></div>
<div class="content"></div>
<div class="content"></div>
</div>
css
.container{
overflow: scroll;
}
.content{
height: 100px;
margin: 5px;
background: blue;
display: inline-block;
width: 25%;
}
试图让蓝色框都在一条线上。
添加
white-space: nowrap
到container
因此容器样式变为:
.container{
overflow-x: scroll;
white-space: nowrap;
}
white-space: nowrap means Sequences of whitespace will collapse into a single whitespace. Text
will never wrap to the next line. The text continues on the same line until a < br > tag is encountered
参见 link:“http://codepen.io/anon/pen/xGQXRz”
试试这个。只需更改 .content
class.
的宽度
.container{
overflow: scroll;
}
.content{
height: 100px;
margin: 5px;
background: blue;
display: inline-block;
width: 17%;
}
<div class="container">
<div class="content"></div>
<div class="content"></div>
<div class="content"></div>
<div class="content"></div>
<div class="content"></div>
</div>
我想这样做,如果容器内的内联块超过容器的宽度,它们会拉伸而不是下降到下方。
我把我的意思写成代码笔:http://codepen.io/anon/pen/pJQWbR
<div class="container">
<div class="content"></div>
<div class="content"></div>
<div class="content"></div>
<div class="content"></div>
<div class="content"></div>
</div>
css
.container{
overflow: scroll;
}
.content{
height: 100px;
margin: 5px;
background: blue;
display: inline-block;
width: 25%;
}
试图让蓝色框都在一条线上。
添加
white-space: nowrap
到container
因此容器样式变为:
.container{
overflow-x: scroll;
white-space: nowrap;
}
white-space: nowrap means Sequences of whitespace will collapse into a single whitespace. Text will never wrap to the next line. The text continues on the same line until a < br > tag is encountered
参见 link:“http://codepen.io/anon/pen/xGQXRz”
试试这个。只需更改 .content
class.
.container{
overflow: scroll;
}
.content{
height: 100px;
margin: 5px;
background: blue;
display: inline-block;
width: 17%;
}
<div class="container">
<div class="content"></div>
<div class="content"></div>
<div class="content"></div>
<div class="content"></div>
<div class="content"></div>
</div>