SASS variables and inheritance

前端 未结 4 453
盖世英雄少女心
盖世英雄少女心 2021-01-07 03:13

Suppose I have two virtually identical HTML structures, but with different class names. They only differ by a few variables, like width and h

4条回答
  •  没有蜡笔的小新
    2021-01-07 03:44

    Variables in SASS are only scoped to the block they appear in. Your first .widget-a declaration and the one declaring both A and B are two separate scopes. You'll have to do something like this (assuming you need to use the widths more than once):

    $wbackground: red;
    
    .widget-a {
        $wawidth: 50px; /* widget A width */
        button {
            background: $wbackground;
            width: $wawidth;
        }
    }
    
    .widget-b {
        $wbwidth: 100px; /* widget B width */
        button {
            background: $wbackground;
            width: $wbwidth;
        }
    }
    

提交回复
热议问题