我需要创建一个包含多个其他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不包装?


当前回答

<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>

其他回答

尝试使用空格:nowrap;在容器样式中(而不是overflow: hidden;)

你可以使用

display: table;

对于您的容器,因此避免溢出:隐藏;。如果你只是为了扭曲而使用它,它应该能起作用。

尽量使用宽度:3000px;以IE为例。

以上这些方法对我都没用。

在我的例子中,我需要向我创建的用户控件添加以下内容:

display:inline-block;

使用display:flex和white-space:nowrap

p{ display:flex; white-space:nowrap; overflow:auto; } <h2>Sample Text.</h2> <p>Some example text that will not wrap..lla et dictum interdum, nisi lorem egestas odio, vitae scelerisque enim ligula venenatis dolor. Maecenas nisl est, ultrices nec congue eget, auctor vitae massa. Fusce luctus vestibulum augue ut aliquet. Mauris ante ligula, facilisis sed ornare eu, lobortis in odio. Praesent convallis urna a lacus interdum ut hendrerit risus congue. Nunc sagittis dictum nisi, sed ullamcorper ipsum d</p> <h3>Then some other text</h3>