Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

@supports css calc function

Tags:

css

css-calc

Is there a way to use the calc function in @supports(propertyName, value)? i mean where <supports_condition> is only for the calc function.

@supports ( <supports_condition> ) {
    .col-3 {
    width: calc(25% - 20px/4)
    }
    .col-4 {
        width: calc(33.3333333% - 20px/3)
    }
    .col-6 {
        width: calc(50% - 20px/2)
    }
}
like image 815
Gildas.Tambo Avatar asked Mar 12 '15 02:03

Gildas.Tambo


People also ask

What does CALC () do in CSS?

calc() The calc() CSS function lets you perform calculations when specifying CSS property values. It can be used anywhere a <length> , <frequency> , <angle> , <time> , <percentage> , <number> , or <integer> is allowed.

Can I use Calc in padding?

A solution for you would be to use CSS calc, it has good browser support and fixes your issue in quite a simple manner. The only downside here is that it doesn't calculate the padding-top in % but you simply cannot calculate padding-top in % from the height of the element unless you use javascript.

How do you calculate height in CSS?

In this case we use jquery to calculate the height of content div area. But now using CSS we can set height without making header and footer height fixed or using jquery function. We use css property height: calc( 100% - div_height ); Here, Calc is a function.


2 Answers

Support for @supports is far, far more restricted than calc() because the latter was introduced several years earlier (most notably, IE doesn't support @supports at all, whereas it has supported calc() since version 9 which came out almost exactly 4 years ago). If you were to use them together, every browser that supports @supports would match that rule, and any browser that supports calc() but not @supports would ignore that rule. In other words, if you were to use them together you'd be reducing the number of browsers that can use the calc() function by preventing some of them from ever seeing your declarations.

Fortunately, since calc() is a value, in lieu of a not-yet-existing @supports authors could simply take advantage of the cascade by providing fallback declarations for when calc() isn't supported:

width: 95px;
width: calc(25% - 20px/4);
like image 59
BoltClock Avatar answered Nov 15 '22 10:11

BoltClock


You can see if any calc condition works in the @support condition, and if it does, tell it to do what you actually want. So something like: JS Fiddle

@supports (width: calc(100% - 80em)) {
    div {
        width: calc(100% - 3em);
    }
}

See This line for Mozilla's documentation.

like image 30
Derek Story Avatar answered Nov 15 '22 10:11

Derek Story