Can a CSS class inherit one or more other classes?

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

    In specific circumstances you can do a "soft" inheritance:

    .composite
    {
    display:inherit;
    background:inherit;
    }
    
    .something { display:inline }
    .else      { background:red }
    

    This only works if you are adding the .composite class to a child element. It is "soft" inheritance because any values not specified in .composite are not inherited obviously. Keep in mind it would still be less characters to simply write "inline" and "red" instead of "inherit".

    Here is a list of properties and whether or not they do this automatically: https://www.w3.org/TR/CSS21/propidx.html

提交回复
热议问题