How can I apply styles to multiple classes at once?

前端 未结 5 1222
刺人心
刺人心 2020-11-29 21:10

I want two classes with different names to have the same property in CSS. I don\'t want to repeat the code.

相关标签:
5条回答
  • 2020-11-29 21:39

    You can have multiple CSS declarations for the same properties by separating them with commas:

    .abc, .xyz {
       margin-left: 20px;
    }
    
    0 讨论(0)
  • 2020-11-29 21:47

    just seperate the class name with a comma.

    .a,.b{
    your styles
    }
    
    0 讨论(0)
  • 2020-11-29 21:50

    Don’t Repeat Your CSS

     a.abc, a.xyz{
        margin-left:20px;
     }
    

    OR

     a{
        margin-left:20px;
     }
    
    0 讨论(0)
  • 2020-11-29 22:03
    .abc, .xyz { margin-left: 20px; }
    

    is what you are looking for.

    0 讨论(0)
  • 2020-11-29 22:04

    If you use as following, your code can be more effective than you wrote. You should add another feature.

    .abc, .xyz {
    margin-left:20px;
    width: 100px;
    height: 100px;
    } 
    

    OR

    a.abc, a.xyz {
    margin-left:20px;
    width: 100px;
    height: 100px;
    } 
    

    OR

    a {
    margin-left:20px;
    width: 100px;
    height: 100px;
    } 
    
    0 讨论(0)
提交回复
热议问题