How to make a DIV not wrap?

HtmlCssWord WrapNowrap

Html Problem Overview


I need to create a container DIV style that contains multiple other DIV's. It is asked that these DIV's wouldn't wrap if the browser window is resized to be narrow.

I tried to make it work like below.

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

This works in most cases. However, in some special cases, the rendering is incorrect. I found the container DIV change to 3000px width in RTL of IE7; and it turns to be messy.

Is there any other way to make a container DIV not to wrap?

Html Solutions


Solution 1 - Html

Try using white-space: nowrap; in the container style (instead of overflow: hidden;)

Solution 2 - Html

If I don't want to define a minimal width because I don't know the amount of elements the only thing that worked to me was:

display: inline-block;
white-space: nowrap;

But only in Chrome and Safari :/

Solution 3 - Html

The following worked for me without floating (I modified your example a little for visual effect):

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

The divs may be separated by spaces. If you don't want this, use margin-right: -4px; instead of margin: 5px; for .slide (it's ugly but it's a tricky problem to deal with).

Solution 4 - Html

The combo you need is

white-space: nowrap

on the parent and

display: inline-block; // or inline

on the children

Solution 5 - Html

This worked for me:

.container {
  display: inline-flex;
}

.slide {
  float: left;
}

<div class="container">
  <div class="slide">something1</div>
  <div class="slide">something2</div>
  <div class="slide">something3</div>
  <div class="slide">something4</div>
</div>

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

Solution 6 - Html

overflow: hidden should give you the correct behavior. My guess is that RTL is messed up because you have float: left on the encapsulated divs.

Beside that bug, you got the right behavior.

Solution 7 - Html

Use display:flex and 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>

Solution 8 - Html

Try to use width: 3000px; for the case of IE.

Solution 9 - Html

None of the above worked for me.

In my case, I needed to add the following to the user control I had created:

display:inline-block;

Solution 10 - Html

The min-width property does not work correctly in Internet Explorer, which is most likely the cause of your problems.

Read info and a brilliant script that fixes many IE CSS problems.

Solution 11 - Html

you can use

display: table;

for your container and therfore avoid the overflow: hidden;. It should do the job if you used it just for warpping purpose.

Solution 12 - Html

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

Solution 13 - Html

The <span> tag is used to group inline-elements in a document.
(source)

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionMorgan ChengView Question on Stackoverflow
Solution 1 - HtmlnotkwiteView Answer on Stackoverflow
Solution 2 - HtmlfguillenView Answer on Stackoverflow
Solution 3 - HtmlJSiderisView Answer on Stackoverflow
Solution 4 - HtmldanschView Answer on Stackoverflow
Solution 5 - HtmlTurakoView Answer on Stackoverflow
Solution 6 - HtmlYuval AdamView Answer on Stackoverflow
Solution 7 - HtmlkishoreView Answer on Stackoverflow
Solution 8 - HtmlAndres GRView Answer on Stackoverflow
Solution 9 - HtmlJ-DawGView Answer on Stackoverflow
Solution 10 - HtmlAistinaView Answer on Stackoverflow
Solution 11 - HtmlPakaView Answer on Stackoverflow
Solution 12 - HtmlAnil KhatourView Answer on Stackoverflow
Solution 13 - HtmlMikeView Answer on Stackoverflow