Can a CSS class inherit one or more other classes?

前端 未结 30 3180
挽巷
挽巷 2020-11-22 00:01

I feel dumb for having been a web programmer for so long and not knowing the answer to this question, I actually hope it\'s possible and I just didn\'t know about rather tha

30条回答
  •  梦如初夏
    2020-11-22 00:40

    There are tools like LESS, which allow you to compose CSS at a higher level of abstraction similar to what you describe.

    Less calls these "Mixins"

    Instead of

    /* CSS */
    
    #header {
      -moz-border-radius: 8px;
      -webkit-border-radius: 8px;
      border-radius: 8px;
    }
    
    #footer {
      -moz-border-radius: 8px;
      -webkit-border-radius: 8px;
      border-radius: 8px;
    }
    

    You could say

    /* LESS */
    
    .rounded_corners {
      -moz-border-radius: 8px;
      -webkit-border-radius: 8px;
      border-radius: 8px;
    }
    
    #header {
      .rounded_corners;
    }
    
    #footer {
      .rounded_corners;
    }
    

提交回复
热议问题