views:

46

answers:

2

Hi, I am doing some of my first web dev, and had a question about the max-height css property.

Here's my code:

div{
     max-height:10px; 
}

Whenever I create a new div, everything works fine, but when I add any sort of other element between the div tags, the height of the div increase by around 10 pixels (I'm guessing). Is there any way to override this? I want to have a div with text in it where there is almost no border around the text.

Thanks for any help! -Matt

A: 

You could try adding overflow:hidden; to your css for the div.

Josiah
+2  A: 

Sometimes even the default font-size affect the division height. so try overflow:hidden or font-size:10px.

I think this can solve your problem

Starx
+1, but it's not really that the div is getting bigger, it's that the content is spilling out of it. If you examine the div you'll notice that its height is still 10px. Regardless, both of your solutions work great. :)
Faisal
@Faisal, thats because you have choosen your division to have only 10px as its maximum height, a longer element inside it will obviously pop out. Try setting the max height of inside elements instead, then the parent will follow
Starx
Thanks for the quick response, Starx. Using overflow:hidden seemed to help. It at least limited the height of the div, though now for some reason the text gets pushed off of the bottom of the div. Any ideas?
mag725
@mag, decrease the font size to 10 px
Starx