Calculate a percent with SCSS/SASS

前端 未结 3 414
Happy的楠姐
Happy的楠姐 2020-12-13 05:34

I want to set a width in percentage in scss via calculation, but it gives me errors..

Invalid CSS after \"...-width: (4/12)%\": expected expression (e

相关标签:
3条回答
  • 2020-12-13 05:42

    Another way:

    $my_width: 4/12*100%;
    
    div{
    width: $my_width; // 33.33333%
    }
    

    Sass will output the value in %.

    0 讨论(0)
  • 2020-12-13 05:47

    Have you tried the percentage function ?

    $my_width: percentage(4/12);
    div{
    width: $my_width;
    }
    
    0 讨论(0)
  • 2020-12-13 06:08

    I was able to make it work this way:

    div{
       width: (4/12)* 1%;
       }
    

    This way you don't need to use any special function.

    0 讨论(0)
提交回复
热议问题