Can a CSS class inherit one or more other classes?

前端 未结 30 3217
挽巷
挽巷 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:33

    No you can't do something like

    .composite 
    {
       .something;
       .else
    }
    

    This are no "class" names in the OO sense. .something and .else are just selectors nothing more.

    But you can either specify two classes on an element

    ...

    or you might look into another form of inheritance

    .foo {
      background-color: white;
      color: black;
    }
    
    .bar {
      background-color: inherit;
      color: inherit;
      font-weight: normal;
    }
    

    Hello, world

    Where the paragraphs backgroundcolor and color are inherited from the settings in the enclosing div which is .foo styled. You might have to check the exact W3C specification. inherit is default for most properties anyway but not for all.

提交回复
热议问题