Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using multiple CSS Units in one line

Is it possible to use multiple units in one line of CSS code? For example:

width: 20% + 5px;

Im presuming not. If so, how do you do it in a language such as javascript?

like image 662
Legatro Avatar asked Sep 11 '26 10:09

Legatro


1 Answers

As Sirko pointed out, there is calc(). Unfortunately there is a catch with using that function: out of the major browsers IE <9 and Opera does NOT support it.

If all you want is to include a padding then you can achieve the same thing with the box-sizing attribute set to border-box that has far better browser support. For IE<8 there is also a polyfill available.

.span20 {
    -moz-box-sizing: border-box;
         box-sizing: border-box;

    width: 20%;
    padding: 5px;
    float: left;
}

Here is a jsfiddle demonstrating the above.

like image 67
Spoike Avatar answered Sep 14 '26 00:09

Spoike



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!