1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Is there any way to set a min height for a div?

Discussion in 'CSS' started by Imozeb, Mar 25, 2010.

  1. #1
    I have a div that is populated dynamicly. When there is no data in it it shrinks to 0px. I was wondering if there is a way to set a min height for the div but no max height? Is this possible?

    Thanks.

    ~imozeb
     
    Imozeb, Mar 25, 2010 IP
  2. ampg-it

    ampg-it Peon

    Messages:
    75
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    here you go.

    <style type="text/css">
    .box {
    height:50px;
    width:100px;
    background-color: #000000;
    }
    </style>

    <div class="box"></div>
     
    ampg-it, Mar 25, 2010 IP
  3. Imozeb

    Imozeb Peon

    Messages:
    666
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I have tried that (height:50px; ) and it sets the height to 50 pixel like it should but when the data is greater than 50px the container won't expand.
     
    Imozeb, Mar 25, 2010 IP
  4. Tibiacity

    Tibiacity Active Member

    Messages:
    190
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    73
    #4
    Haven't tested it myself for the height of an element, but check this: http://www.doxdesk.com/software/js/minmax.html

    An alternative would be to check with php or asp if the content is empty and then use inline style="height: 50px;" if it's empty.
     
    Tibiacity, Mar 25, 2010 IP
  5. drhowarddrfine

    drhowarddrfine Peon

    Messages:
    5,428
    Likes Received:
    95
    Best Answers:
    7
    Trophy Points:
    0
    #5
    How about 'min-height:50px'?
     
    drhowarddrfine, Mar 25, 2010 IP
    Brad Proctor likes this.
  6. mnvlxxx

    mnvlxxx Peon

    Messages:
    47
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Place that div inside a table with fixed height like this:
    <table height="50">
    <tr>
    <td>
    <div style="height:100%;">div content</div>
    </td>
    </tr>
    </table>

    Table will automaticaly expand when needed.
     
    mnvlxxx, Mar 25, 2010 IP
  7. drhowarddrfine

    drhowarddrfine Peon

    Messages:
    5,428
    Likes Received:
    95
    Best Answers:
    7
    Trophy Points:
    0
    #7
    What a horrible, horrible idea.
     
    drhowarddrfine, Mar 25, 2010 IP
  8. sylverCode

    sylverCode Member

    Messages:
    74
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    43
    #8
    Use:
    #div {min-height:500px; overflow:hidden}
    Code (markup):
    Since min-height is buggy in ie6, you have to add overflow:hidden to make it work properly.

    +1
     
    sylverCode, Mar 25, 2010 IP
    Brad Proctor likes this.
  9. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,998
    Best Answers:
    253
    Trophy Points:
    515
    #9
    Uhm, overflow:hidden is NOT the answer to IE6... and can cause more problems than it solves if you are dicking with height.

    You CAN make min-height that works in IE6/earlier really easy though...

    
    #div {
      min-height:500px;
    }
    
    * html #div {
      height:500px;
    }
    
    Code (markup):
    See, there's a really big bug in IE6 where it treats height as min-height. STANDARDS compliant browsers you want to use min-height, using * html to target just IE6/earlier with height makes IE6 work without screwing up the other browsers.

    ... even scarier, it validates now.

    Oh, and when someone tells you to wrap content in a table just for min-height, you tell them to shove it up their...
     
    deathshadow, Mar 27, 2010 IP
  10. Imozeb

    Imozeb Peon

    Messages:
    666
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #10
    Thanks. I didn't know about the * operator.
     
    Imozeb, Mar 28, 2010 IP
  11. haswow

    haswow Guest

    Messages:
    48
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #11
    min-height:50px will work in all browsers except internet explorer.To do this in ie you have to use a javascript code in Css.
    I couldn't remember the actual code, you can google it.
     
    haswow, Mar 28, 2010 IP
  12. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,998
    Best Answers:
    253
    Trophy Points:
    515
    #12
    Hah, I love how people respond without reading the thread.... and how people assume you "have to use javascript" for *** you don't need javascript for... or make generalized statements about IE that are only true of IE6/earlier.

    /FAIL/
     
    deathshadow, Mar 29, 2010 IP
  13. sylverCode

    sylverCode Member

    Messages:
    74
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    43
    #13
    I see, thanks! :)

    You have to use "* html" in order for this hack to work.

    When you use just "*", the browser targets all the CSS selectors that it has in its database, which is not recommended because it will slow down page loading considerably.
     
    sylverCode, Mar 29, 2010 IP