In the following example, the bottom padding is ignored, and the text flows to the bottom of the element before hiding. What is causing this?
<div style="overflow: hidden; width: 300px; height: 100px; padding: 50px;">
<p>Hello, this is text.</p>
<p>Hello, this is text.</p>
<p>Hello, this is text.</p>
<p>Hello, this is text.</p>
<p>Hello, this is text.</p>
<p>Hello, this is text.</p>
</div>
A view with Firebug (purple is padding, blue is actual content area):
I know this is a bit old now, but I had this issue recently and fixed it by adding an additional inner div which has a margin.
http://jsfiddle.net/7xhuF/1/
I'm a little late to the game, but Padding renders internal content the same as the content area (that's one of the ways it's different from a Border or a Margin).
Learn More About the Box Model
You'll notice this most clearly if you set background colors or background images to divs with padding. The background color/image extends beyond the content portion and appears inside the padding area.
The solution is to set a margin instead. or a combination of a padding and margin (where there is no bottom padding, but instead a bottom margin of equal height.
http://jsfiddle.net/Uhg38/
I don't think you're going to get the effect you are looking for without adding a 2nd div.
http://jsfiddle.net/Mxhzf/
(background color added to make it clear what is happening)
HTML:
CSS:
If your CSS uses
padding-bottom
andoverflow:hidden
together,it will cause the problem you describe.The best solution is:
Click here for live demo
The bottom padding exists but the content pushes the bottom padding down and is not visible because of overflow:hidden. What you can do is place the content in a container like so:
You can play with the fiddle here - http://jsfiddle.net/BMZeS/
Hope this helps.
I prefer to use as few
<div>
s as possible.http://jsfiddle.net/bgaR9/
naturally in a world without IE < 9