tags:

views:

31

answers:

3

I'm trying to replace some layouts table layouts with css layouts and have this code:

<html>
<head>
 <style type="text/css">
  #grid{
   border:solid;
   border-width:1px;
   border-color:#000000;
   width:300px;
   max-width:300px;
   min-width:300px;
   overflow:hidden;
   font-size:14px;
  }

  #grid .item{
   text-align:center;
   width:33%;
   margin-top:2px;
   margin-bottom:2px;
   float:left;
  }
 </style>
</head>
<body>
 <div id="wagerStream">
  <div id="grid">
   <div class="item">item1</div>
   <div class="item">item2</div>
   <div class="item">item3</div>
   <div class="item">item4</div>
   <div class="item">item5</div>
   <div class="item">item6</div>
   <div class="item">item7</div>
   <div class="item">item8</div>
   <div class="item">item9</div>
  </div>
  <div id="grid">
   <div class="item">item1</div>
   <div class="item">item2</div>
   <div class="item">item3</div>
   <div class="item">item4 with wrapping text</div>
   <div class="item">item5</div>
   <div class="item">item6</div>
   <div class="item">item7</div>
   <div class="item">item8</div>
   <div class="item">item9</div>
  </div>
 </div>
</body>
</html>

As you can see I have a problem with the way the last three items display when wrapping text occurs and would to know what would be a good css solution.

A: 

set additional two styles on item class:

white-space: nowrap;
overflow: hidden;

That should do the trick.

Robert Koritnik
thanks, that works but is there a way to keep the text and make item5 and item6 increase their height to match item4's instead?
Dan
Unfortunately not without javascript or wrapping rows together.
Robert Koritnik
Ok,I guess I'll use javascript to set the others elements height equal to the biggest one.
Dan
You can find scripts for that on the net http://www.google.com/search?q=javascript+equal+height+columns
Robert Koritnik
A: 

You will need to specify a height to the .item. Because floating elements always set their height to the minimum they need. So, add the following line to your .item

height:<amount>px;
Kevin
A: 

The only solution I could think of without using JavaScript and without specifying a set height to your items, is to wrap every 3 items in a row.

<div id="grid">
   <div class="item-row">
      <div class="item">item1</div>
      <div class="item">item2</div>
      <div class="item">item3</div>
   </div>
   <div class="item-row">
      <div class="item">item4 with wrapping text</div>
      <div class="item">item5</div>
      <div class="item">item6</div>
   </div>
   <div class="item-row">
      <div class="item">item7</div>
      <div class="item">item8</div>
      <div class="item">item9</div>
   </div>
</div>

You'd want to have overflow:hidden applied to item-row to contain the floated items.

Scott Christopherson