0

I have a div with its content (list inside),

<div id="container">
     <ul id="list">
       <li>
         <div class="title">
              something
         </div>
         <div class="text">
             something again
         </div>
       </li>
        <li>
         <div class="title">
              something
         </div>
         <div class="text">
             something again
         </div>
       </li>
    </ul>
</div>

And my items from list are displayed float:left, and I want to the div container expand in height as its content.

#container{ 
    position: relative; 
    width: 100%;    
    padding-bottom: 30px;       
}

#list{
    position: relative;
    padding-top: 80px;
    width: 95%;
    /*height: 100%;*/
    padding-bottom: 10px;
}

#list li{
    position: relative;
    float: left;    
    list-style: none outside none;
    width: 20%;
    height: 170px;  
    /*border:1px solid black;*/
}
halfer
  • 19,824
  • 17
  • 99
  • 186
Nuno
  • 112
  • 2
  • 12
  • some like expand menu ? – Alex Wilson Jul 17 '14 at 14:38
  • So where is the `float: left;` in your CSS? You are missing a closing angle bracket (`>`) off your `#container` div by the way. – Andy Jul 17 '14 at 14:43
  • Please show a more complete example of your code. If possible create a jsfiddle so that we can see what the problem is. – Elmer Jul 17 '14 at 14:47
  • Its more like, I have that Div, container, and, my list has 13 elements. And for instance, my container has background-color: red; and I want that div container expand based on its 13 elements. I have 5-5-3 . – Nuno Jul 17 '14 at 15:21

2 Answers2

4

You have several options:

  1. Clearfix on the container:

    #container:after {
        clear: both;
        content: "";
        display: table;
    }
    
  2. The use of overflow:

    #container {
        overflow: hidden; /* or: auto | scroll */
    }
    
  3. Float the container:

    #container {
        float: left;
    }
    
  4. Using inline-block instead of float for the list items:

    #container ul li {
        display: inline-block;
        float: none;
    }
    
Community
  • 1
  • 1
Adrift
  • 58,167
  • 12
  • 92
  • 90
1

Try this approach...

li {
    display: inline-block;
    float: none; /* only if you have this set as you mentioned in your post */
}

#container {
  height: auto;
}
  • Thanks for answering, but as I said above, i think my "overflow:hidden" was missing. :) – Nuno Jul 17 '14 at 15:27