LESSCSS method with IE FIlter Alpha Opacity CSS

后端 未结 5 1336
终归单人心
终归单人心 2021-02-04 00:19

I am using LESSCSS. I\'m trying to create a method for opacity:

.opacity (@opacity) 
{
    opacity: @opacity;
    -ms-filter: \"progid:DXImageTransform.Microsof         


        
5条回答
  •  借酒劲吻你
    2021-02-04 00:49

    You need to prefix the string with ~, like so:

    -ms-filter: ~"progid:DXImageTransform.Microsoft.Alpha(opacity=50)";
    

    From the docs: Escaping

    UPDATE: you need to wrap the variable names in curly braces.

    .opacity (@opacity) {
        opacity: @opacity;
        -ms-filter: ~`"progid:DXImageTransform.Microsoft.Alpha(opacity=(" + "@{opacity}" * 100 + "))"`; 
        filter: ~`"alpha(opacity = (" + "@{opacity}" * 100 + "))"`;
    }
    

    Here's what's happening: after the prefix, wrap the entire expression in backticks so that it is evaluated as JavaScript. Then you can add the result of the multiplication to the rest of the string; you also need to wrap the LESS variable in quotes and curly braces so the compiler can evaluate it before the multiplication.

    This has been a cool question; I didn't actually know LESS could do this.

提交回复
热议问题