Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SASS: width: 100% - 20px - is it possible?

Tags:

css

sass

I use padding in many of my projects, and it would be handy if I could substract the padding from the width, it is possible ?

if:

width:100%; 

and

padding: 20px; 

=

100% - 40px ?  
like image 893
jakobk Avatar asked Nov 29 '22 15:11

jakobk


2 Answers

You can use box-sizing: border-box to make the padding be counted as part of the width.

div {
    -moz-box-sizing: border-box;
    -webkit-box-sizing: border-box;
    box-sizing: border-box;
}

Here's a quick demonstration: http://jsfiddle.net/thirtydot/DNs2u/

More info:

  • http://caniuse.com/css3-boxsizing
  • http://www.w3.org/TR/css3-ui/#box-sizing0
  • https://developer.mozilla.org/en/CSS/box-sizing
like image 83
thirtydot Avatar answered Dec 08 '22 01:12

thirtydot


width: calc(100% - 40px);

more calc() uses: CSS Tricks: A Couple of Use Cases for Calc()

like image 23
Ange Avatar answered Dec 08 '22 01:12

Ange