How to reuse css class content in another class without copying?

前端 未结 8 1051
北恋
北恋 2021-02-18 14:07

Is it possible to use existing css class as content in another class ?

I mean something like:

Contained in some library:
.class1 { text-indent: 100 }

 I         


        
8条回答
  •  我在风中等你
    2021-02-18 14:27

    CSS has no means to reference one rule-set from another.

    Your options include:

    Using multiple selectors for things with common rules

    .menu,
    .nav {
        font-weight: bold;
    }
    
    .nav {
        display: inline-block;
    }
    

    Using multiple classes on a single element

    .menu {
         font-weight: bold;
    }
    
    .nav {
         display: inline-block;
    }
    
    

    Generating your CSS programatically

    For example, with SASS

    @mixin menu {
        font-weight: bold;
    }
    
    .nav {
        display: inline-block;
        @include menu;
    }
    

提交回复
热议问题