css - 100% + padding?

前端 未结 2 1565
旧巷少年郎
旧巷少年郎 2021-01-01 18:57

As most people know,

a 100% div with a 5px padding is actually 100% + 10px wide.

One obvious solution to this is to wrap the child div in a wrapper that has

2条回答
  •  有刺的猬
    2021-01-01 19:47

    You should look into the box-sizing CSS property...

    • http://www.w3.org/TR/css3-ui/#box-sizing
    • https://developer.mozilla.org/en/CSS/box-sizing

    I put together an example to show you how this works and the difference between having the box-sizing property and not having it. Check out the fiddle...

    http://jsfiddle.net/UnsungHero97/bKsad/2/

    Note that this won't work in IE7 or below :/

    I hope this helps.
    Hristo

提交回复
热议问题