drummondj
drummondj

Reputation: 1483

IE float div wrapping

I'm having a problem with floating divs and IE7. For example, the following HTML code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns='http://www.w3.org/1999/xhtml' lang='en' xml:lang='en'>
  <head>
    <title>IE Float Test</title>
    <style>
      .container {
        width: 200px;
        background: #ddd;
        overflow: hidden;
      }
      .item {
        float: left;
        padding: 5px;
        background: #eee;
        margin: 5px;
      }
    </style>
  </head>
  <body>
    <div class="container">
      <div class="item">This is a item</div>
      <div class="item">This is another item</div>
      <div class="item">Last item</div>
    </div>
  </body>
</html>

Give's the following in chrome (plus other major browsers):

Chrome Result

But, the following in IE7:

IE Result

How do I get IE7 to move the item div to the next vertical position if it is too wide?

Many thanks, John.

Upvotes: 4

Views: 2641

Answers (3)

saille
saille

Reputation: 9181

If you want the items stacked, there is no need to "float:left" in your ".item" CSS style. Block level elements like <div> appear stacked by default.

Upvotes: 0

thirtydot
thirtydot

Reputation: 228162

Adding white-space: nowrap to .item works: http://jsbin.com/ifexuf/2

Is that acceptable?

Upvotes: 4

user194076
user194076

Reputation: 9017

You need to add min-width property to the .item

Upvotes: 0

Related Questions