1252748
1252748

Reputation: 15379

padding increases width and height of div

how can I modify these divs so that when I change their padding, their height and width do not expand? I have tried to implement

.outer, .inner {
    display: block;
}

.outer {
    /* specify fixed width */
    width: 300px;
    padding: 0;
}

.inner {
    /* specify padding, can be changed while remaining fixed width of .outer */
    padding: 5px;
}

from here

by giving the parent divs fixed_width and relative_container width:700px;height:100px; padding:0px;, but when I apply padding to .content or .obscure, the divs expand to cover .extra_margins below. Thanks!

http://jsfiddle.net/loren_hibbard/ZmJ9R/

Upvotes: 5

Views: 5666

Answers (1)

Kevin Boucher
Kevin Boucher

Reputation: 16705

You can use CSS3 box-sizing property to do this:

box-sizing: border-box;

http://css-tricks.com/box-sizing/

Supported in IE8+ but some browsers may require a prefix:

http://caniuse.com/css3-boxsizing

Upvotes: 11

Related Questions