Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS padding overrides overflow?

Whats happening here ?

#agendaTitle{
    margin:0;
    padding:20em 0em 0em 0.75em;
    height:3em;
    overflow:hidden;
    background-color:#ff00ff;
}

The top padding is ridiculously high just to demonstrate - with a realistic requirement the div still increases height proportionally.

Surely the overflow:hidden means I should just see a block of colour ? Occurs in FF and IE

like image 835
Datadimension Avatar asked Sep 27 '13 13:09

Datadimension


People also ask

Why is padding causing overflow?

When padding is added to an element with a width or a height of 100% it causes that element to overflow. It's no surprise since padding creates extra space within an element.

What is CSS overflow clip?

The CSS overflow-clip-margin property determines how far the overflow of an element can go beyond the element's box before being clipped. This area is called the overflow clip edge.


1 Answers

In the default content-box box model on a display: block element, padding and height are added together to determine the total height of the element. overflow only affects things outside the box (outside of height + padding + border).

If you want border and padding subtracted from specified height rather than added, use box-sizing: border-box.

like image 128
Ennui Avatar answered Oct 24 '22 13:10

Ennui