以下是一个小例子:http://www.cssdesk.com/QXmaG
HTML:
<div id="blockHolder">
<div class="inlineblock"></div>
<div class="inlineblock"></div>
<div class="inlineblock"></div>
<div class="inlineblock"></div>
</div>
CSS:
body {
font-family: 'Lucida Grande', 'Helvetica Neue', Helvetica, Arial, sans-serif;
padding: 100px;
font-size: 13px;
}
.inlineblock{
width:400px;
height:200px;
display:inline-block;
background:red;
white-space: nowrap;
}
#blockHolder{
width:auto;
height:100%;
}
我希望inline-block
项在此示例中的父容器#blockHolder
中保持排列(水平)。
为什么white-space:nowrap
不起作用,我怎样才能达到预期效果?
谢谢!
答案 0 :(得分:2)
将whitespace: nowrap
添加到#blockHolder
:http://jsfiddle.net/3LQJG/。
#blockHolder {
white-space: nowrap;
}
答案 1 :(得分:1)
white-space:nowrap指定段落中的文本永远不会换行,对div不起作用。 您需要为#blockHolder添加宽度。
答案 2 :(得分:0)
使用display:table-cell;
.inlineblock{
width:400px;
height:200px;
display:table-cell;
background:red;
}
答案 3 :(得分:0)
在body
中,添加:
width: 100%;
<强> CSS:强>
body {
font-family: 'Lucida Grande', 'Helvetica Neue', Helvetica, Arial, sans-serif;
padding: 100px;
font-size: 13px;
width: 100%;
}