Whitespace preservation in LESS escaping for calc operands in CSS3

前端 未结 2 1698
执念已碎
执念已碎 2021-01-12 02:19

I would like to express the following CSS in LESS:

.a {
    min-height: calc(2em + 4px);
}

So, in order to prevent LESS from attempting a c

相关标签:
2条回答
  • 2021-01-12 02:35

    This is kind of an old post but I wanted to show you a simple mathematic workaround for this.

    I also have this issue with my minifying engine. Mine works fine with substraction but remove whitespace in addition. If someone have the same problem, this is the simplest workaround.

    If you want this:

    .a {
        min-height: ~'calc(2em + 4px)';
    }
    

    Write it as this instead:

    .a {
        min-height: ~'calc(2em - -4px)';
    }
    
    0 讨论(0)
  • 2021-01-12 02:42

    You must use "escape" function applying it in a different way:

    FIRST OPTION:

    .a {
        min-height:calc(~"2em + " 4px);
    }
    

    SECOND OPTION: Limiting use of escape character ~ only to + symbol:

    .a {
        min-height:calc(2em ~"+" 4px);
    }
    

    Both of them will result in the following processed CSS:

    .a {
        min-height: calc(2em + 4px);
    }
    
    0 讨论(0)
提交回复
热议问题