How to create a group of css multiple classes same style?

Dung Do Tien Aug 01 2021 56

Hi Guys, I just began to study CSS(Cascading Style Sheets). I have a problem, I have three classes as below:

h1{
   color: #333;
   font-family: 'arial';
}

h2{
   color: #333;
   font-family: 'arial';
}

p{
   color: #333;
   font-family: 'arial';
}

You can see they are in the same style. I feel they're so long and redundant of code. How to create a group css multiple classes with the same style? 

Thanks for any suggestions.

Have 2 answer(s) found.
  • S

    Sáng Cao Aug 01 2021

    h1, h2, p{
       color: #333;
       font-family: 'arial';
    }

    It's what are you looking for!!

  • Đ

    Đặng Thanh Tuấn Aug 01 2021

    You can use a comma , to help define many classes, ids have the same style. For example:

    h1, h2, p{
       color: #333;
       font-family: 'arial';
    }

     Or

     a, #id, p.heading{
       color: #333;
       font-family: 'arial';
    }
    
Leave An Answer
* NOTE: You need Login before leave an answer

* Type maximum 2000 characters.

* All comments have to wait approved before display.

* Please polite comment and respect questions and answers of others.

Popular Tips

X Close