Do CSS functions exist?

前端 未结 9 1691
我在风中等你
我在风中等你 2021-01-04 11:08

I\'m not sure what to call this, but basically let\'s say I have a style that I use a lot,

.somepattern{
    font-size:16px;
    font-weight:bold;
    borde         


        
9条回答
  •  滥情空心
    2021-01-04 11:53

    You can't programatically control CSS from your markup, but you can use one of the many CSS extensions to make CSS work more like a compiled language.

    http://lesscss.org/

    http://sass-lang.com/

    If we wrote your example in LESS, we'd get something like this:

    .somepattern(@color: red, @size: 16px) {
        font-size:@size;
        font-weight:bold;
        border:2px solid @color;
    }
    

    And then you could use it in your LESS file like so:

    .myclass {
        .somepattern(green, 20px);
    }
    

提交回复
热议问题