Import CSS Selector Styles in Another Selector? (NOT @import)

前端 未结 3 1794
别跟我提以往
别跟我提以往 2021-01-18 18:29

Is there a way to import the styling of a single CSS selector into another CSS selector and add to it or rewrite properties from it.

Let\'s say:

.ori         


        
3条回答
  •  星月不相逢
    2021-01-18 19:20

    You can add the .overwrite selector to the first rule by separating it from the existing selector with a comma (grouping selectors), so the selector rule becomes .original_class, .overwrite:

    .original_class,
    .overwrite {
    background: black;
    color: white;
    }
    .overwrite {
    color: blue;
    border: 1px solid green;
    }
    

    Also, when you write:

    this will replace the attributes of the original CSS class

    there is no such thing as attributes and class in CSS, not with the intended meaning of OOP I guess. There are rules, selector rules (to select HTML id, classes, elements, attributes and other pseudos), declarations, properties and values.

提交回复
热议问题