我需要创建一个包含多个其他DIV的容器DIV样式。如果浏览器窗口的大小被调整为窄,则会询问这些DIV是否不会自动换行。

我试着让它像下面这样工作。

<style>
   .container
   {
      min-width: 3000px;
      overflow: hidden;
   }
   .slide
   {
      float: left;
   }
</style>
<div class="container">
   <div class="slide">something</div>
   <div class="slide">something</div>
   <div class="slide">something</div>
   <div class="slide">something</div>
</div>

这在大多数情况下都有效。然而,在某些特殊情况下,呈现是不正确的。我发现在IE7的RTL中,容器DIV的宽度更改为3000px;结果变得很混乱。

是否有其他方法使容器DIV不包装?


当前回答

这招对我很管用:

.container { 显示:inline-flex; } .slide { 浮:左; } < div class = "容器" > < div class = "幻灯片”> something1 < / div > < div class = "幻灯片”> something2 < / div > < div class = "幻灯片”> something3 < / div > < div class = "幻灯片”> something4 < / div > < / div >

https://css-tricks.com/snippets/css/a-guide-to-flexbox/

其他回答

溢出:隐藏应该给你正确的行为。我的猜测是RTL是混乱的,因为你在封装的divs上有float: left。

除了那个虫子,你的行为还不错。

<span>标记用于对文档中的内联元素进行分组。 (源)

<div style="height:200px;width:200px;border:; white-space: nowrap;overflow-x: scroll;overflow-y: hidden;">
   <p>The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog.The quick brown fox jumps over the lazy dog.The quick brown fox jumps over the lazy dog.
   The quick brown fox jumps over the lazy dog.The quick brown fox jumps over the lazy dog.The quick brown fox jumps over the lazy dog.The quick brown fox jumps over the lazy dog.
   The quick brown fox jumps over the lazy dog.
   The quick brown fox jumps over the lazy dog.The quick brown fox jumps over the lazy dog.The quick brown fox jumps over the lazy dog.The quick brown fox jumps over the lazy dog.
   The quick brown fox jumps over the lazy dog.The quick brown fox jumps over the lazy dog.</p>
</div>

在Internet Explorer中min-width属性不能正确工作,这很可能是您的问题的原因。

阅读信息和 一个出色的脚本,修复了许多IE CSS问题。

以下是我在没有浮动的情况下工作的(为了视觉效果,我稍微修改了你的例子):

.container { white-space: nowrap; /*Prevents Wrapping*/ width: 300px; height: 120px; overflow-x: scroll; overflow-y: hidden; } .slide { display: inline-block; /*Display inline and maintain block characteristics.*/ vertical-align: top; /*Makes sure all the divs are correctly aligned.*/ white-space: normal; /*Prevents child elements from inheriting nowrap.*/ width: 100px; height: 100px; background-color: red; margin: 5px; } <div class="container"> <div class="slide">something something something</div> <div class="slide">something something something</div> <div class="slide">something something something</div> <div class="slide">something something something</div> </div>

div可以用空格分隔。如果你不想这样,使用margin-right: -4px;代替margin: 5px;对于.slide(它很丑,但处理起来很棘手)。