how to inheritance multiples class through sass

前端 未结 2 336
广开言路
广开言路 2021-01-28 03:33
I have a scenario in sass
.A{
    background-color: red;
    Padding :20px;

    h4{ padding-bottom :20px;}
}
// another class

.B{ 
    background-color : blue; 
    pa         


        
相关标签:
2条回答
  • 2021-01-28 03:51

    You really don't save much by using sass/scss for this small of a redundancy

    A solution with scss:

      .a, .b {
        padding: 20px;
        background-color: red;
        & h4 {
          padding-bottom: 20px;
        }
      }
      .b{
        background-color:blue;
      }
    

    That solution in plain css:

      .a, .b {
        padding: 20px;
        background-color: red;
      }
      .a h4, .b h4 {
        padding-bottom: 20px;
      }
      .b {
        background-color: blue;
      }
    

    Here is what that will look like: http://codepen.io/cawoelk/pen/Ciqyw

    0 讨论(0)
  • 2021-01-28 04:16

    The most straight forward way is to use @extend.

    %common_properties {
        padding: 20px;
    
        h4 {
            padding-bottom: 20px;
        }
    }
    
    .a {
        @extend %common_properties; 
        background-color: red;
    }
    
    .b { 
        @extend %common_properties; 
        background-color: blue; 
    }
    
    0 讨论(0)
提交回复
热议问题