Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Dec 2009
    Posts
    13
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Someone explain min-height and max-height

    I've tried to use max-height on a paragraph element, but I didn't see any effect of it.

    Can someone tell me what max-height does and the why one should use max-height instead of just height?

    Examples would be great.

  • #2
    Regular Coder
    Join Date
    Jun 2008
    Posts
    173
    Thanks
    2
    Thanked 9 Times in 9 Posts
    if you specifiy

    max:height:2000px

    but if your content height is more than 2000px then also your content height will still be 2000px. rest of the content above 2000px will not get cut.

    vineet

  • #3
    Master Coder Excavator's Avatar
    Join Date
    Dec 2006
    Location
    Alaska
    Posts
    9,668
    Thanks
    22
    Thanked 1,827 Times in 1,811 Posts
    Hello mobotech,
    max-height sets the maximum height of an element. It can grow up to the height you set but not larger.
    Last edited by Excavator; 12-18-2009 at 08:50 AM. Reason: dyslexic
    Validate often DURING development - Use it like a splelchecker | Debug during Development |Write it for FireFox, ignore IE
    Use the right DocType | Validate your markup | Validate your CSS | Why validating is good | Why tables are bad

  • #4
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,801
    Thanks
    160
    Thanked 2,216 Times in 2,203 Posts
    Blog Entries
    1
    Can someone tell me what max-height does and the why one should use max-height instead of just height?
    Check the output of
    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" xml:lang="en" lang="en">
    <head>
    <title>Box</title>
    <style type="text/css">
    .div1{
    min-height:100px;
    border:1px solid red;
    }
    .div2{
    margin-top:20px;
    max-height:100px;
    border:1px solid black;
    }
    </style>
    
    
    </head>
    
    <body>
    
    
    <div class="outer"> 
      <div class="div1">
      This div has min-height set, so it takes that much height even if the content is too short. It'll automatically fit to the content, if the content size is large.
      </div>
      
      <div class="div2">
      This div has max-height set, so it can't expan beyond that height(the content overflows beyond that limit). If the content is very short, 
      then it takes the height which is required to hold the content. <br> <br>
      Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla ornare pellentesque porttitor. Morbi ullamcorper hendrerit dolor. In hac habitasse platea dictumst. Proin vulputate, lectus vel rhoncus tincidunt, neque sem mollis augue, in lobortis neque libero in nunc. Suspendisse laoreet ullamcorper diam at eleifend. Nam ante arcu, elementum nec sagittis et, aliquam vel nibh. Proin malesuada porta scelerisque. Vivamus auctor, nisi vitae pharetra tincidunt, mauris turpis convallis velit, malesuada bibendum ipsum ipsum in nulla. Nullam viverra, lectus ut iaculis ullamcorper, ipsum tellus eleifend nisi, condimentum fringilla erat purus ut nisi. Integer eget nunc felis. Praesent id erat a mauris aliquet tristique ornare vitae enim. Nulla mollis aliquam arcu eu facilisis. Nulla nec nulla id augue dignissim pellentesque eget vel odio. Nullam non felis a felis hendrerit tempor. Vivamus sit amet quam varius ante hendrerit vulputate. Sed non nisl libero, ac feugiat arcu. Etiam sem velit, tempor imperdiet aliquam congue, lacinia ac lorem.
      </div>
    </div> 
    </body>
    
    </html>
    Quote Originally Posted by Excavator
    max-height sets the maximum height of an element. It can grow larger but not smaller than what you set it to.
    Isn't that the description of min-height?
    Last edited by abduraooft; 12-18-2009 at 08:43 AM.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • Users who have thanked abduraooft for this post:

    mobotech (12-19-2009)

  • #5
    Master Coder Excavator's Avatar
    Join Date
    Dec 2006
    Location
    Alaska
    Posts
    9,668
    Thanks
    22
    Thanked 1,827 Times in 1,811 Posts
    Quote Originally Posted by abduraooft View Post
    Isn't that the description of min-height?
    Oops
    I've fixed it.
    Validate often DURING development - Use it like a splelchecker | Debug during Development |Write it for FireFox, ignore IE
    Use the right DocType | Validate your markup | Validate your CSS | Why validating is good | Why tables are bad

  • #6
    New Coder
    Join Date
    Dec 2009
    Posts
    13
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by abduraooft View Post
    Check the output of
    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" xml:lang="en" lang="en">
    <head>
    <title>Box</title>
    <style type="text/css">
    .div1{
    min-height:100px;
    border:1px solid red;
    }
    .div2{
    margin-top:20px;
    max-height:100px;
    border:1px solid black;
    }
    </style>
    
    
    </head>
    
    <body>
    
    
    <div class="outer"> 
      <div class="div1">
      This div has min-height set, so it takes that much height even if the content is too short. It'll automatically fit to the content, if the content size is large.
      </div>
      
      <div class="div2">
      This div has max-height set, so it can't expan beyond that height(the content overflows beyond that limit). If the content is very short, 
      then it takes the height which is required to hold the content. <br> <br>
      Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla ornare pellentesque porttitor. Morbi ullamcorper hendrerit dolor. In hac habitasse platea dictumst. Proin vulputate, lectus vel rhoncus tincidunt, neque sem mollis augue, in lobortis neque libero in nunc. Suspendisse laoreet ullamcorper diam at eleifend. Nam ante arcu, elementum nec sagittis et, aliquam vel nibh. Proin malesuada porta scelerisque. Vivamus auctor, nisi vitae pharetra tincidunt, mauris turpis convallis velit, malesuada bibendum ipsum ipsum in nulla. Nullam viverra, lectus ut iaculis ullamcorper, ipsum tellus eleifend nisi, condimentum fringilla erat purus ut nisi. Integer eget nunc felis. Praesent id erat a mauris aliquet tristique ornare vitae enim. Nulla mollis aliquam arcu eu facilisis. Nulla nec nulla id augue dignissim pellentesque eget vel odio. Nullam non felis a felis hendrerit tempor. Vivamus sit amet quam varius ante hendrerit vulputate. Sed non nisl libero, ac feugiat arcu. Etiam sem velit, tempor imperdiet aliquam congue, lacinia ac lorem.
      </div>
    </div> 
    </body>
    
    </html>
    Isn't that the description of min-height?
    That helped, thanks.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •