Ger*_*ald 7 html css css-float
如何强制DIV比浏览器窗口更宽,以便水平地容纳它的子项,而不是强制它们在新行上
即用小提琴考虑下面的代码.容器元素中有6个子元素,最小宽度为200px,并且都设置为float:left.当窗口调整得足够宽时,它们都在一行上.当它变窄时,它们开始推动新的行.理想情况下,我希望它们保持在一行并让浏览器显示滚动条.
http://jsfiddle.net/krippy2k/x8sDp/20/
.container {
}
.child-element {
min-width: 200px;
float: left;
height: 100px;
}
.child1 {
background-color: purple;
}
.child2 {
background-color: orange;
}
.child3 {
background-color: black;
}
.child4 {
background-color: green;
}
.child5 {
background-color: blue;
}
.child6 {
background-color: red;
}
<div class="container">
<div class="child-element child1"></div>
<div class="child-element child2"></div>
<div class="child-element child3"></div>
<div class="child-element child4"></div>
<div class="child-element child5"></div>
<div class="child-element child6"></div>
</div>
Run Code Online (Sandbox Code Playgroud)
Mr.*_*ien 13
要么你可以提供一个width父元素,否则你可以使用float: left;与display: inline-block;和white-space: nowrap;
.container {
white-space: nowrap;
}
.child-element {
min-width: 200px;
display: inline-block;
height: 100px;
}
Run Code Online (Sandbox Code Playgroud)
对于white-space的4px每个元素之间,你可以使用margin-left: -4px;
而不是浮动子项,将它们设置为内联块并设置white-space:nowrap在容器上.
.container {
white-space:nowrap;
}
.child-element {
display:inline-block;
min-width: 200px;
height: 100px;
}
Run Code Online (Sandbox Code Playgroud)