Is it possible to do mathematics inside CSS?

前端 未结 5 1072
孤独总比滥情好
孤独总比滥情好 2020-12-01 01:36

I have jquery accorion id #accordion and some of the content inside header class name .simpleColor. Now I want to give a calculated margin to .simp

5条回答
  •  佛祖请我去吃肉
    2020-12-01 01:53

    There's a CSS function called calc that is starting to get pretty good support. The syntax works as followed:

    width: calc(50% - 100px);
    

    (Note that the whitespace around the operators is significant)

    This allows true dynamic computational support in CSS. With a preprocessor, you can only combine static lengths with static lengths, and relative lengths with relative ones.

    Calc is supported since Chrome 19, Firefox 4, and IE9. The feature isn't quite widely supported enough to use it widely, but it will be not too far into the future and it's something to remember and look forward to.

提交回复
热议问题