0

I was wondering if we could add 2 classes in one component. The reason is that I need to add a active class and a categories class for my sideBar is there any posibility of adding 2 classes or an alternative way? heres the code I want to add 2 classes to:

<li><a class="categories" id="Classic" >Classical Music</a></li>
Dev-Siri
  • 592
  • 5
  • 22
  • you can have as many classes on any element as you like `class="categories active a-third-class"` – cloned Apr 15 '22 at 06:08
  • Does this answer your question? [How to apply two CSS classes to a single element](https://stackoverflow.com/questions/5482677/how-to-apply-two-css-classes-to-a-single-element) – Rob Apr 15 '22 at 09:48

2 Answers2

1

Yes you can!

<li><a class="categories active" id="Classic" >Classical Music</a></li>

Just keep a space between the classes.

You can add different classes to one element and one class to different elements as well.

But an element can't have more than one ID and an ID can't be used more than once in a page.

Thanks and best regards!

0

Just add a space to every class, e.g.

.para {
  font-size: larger;
  margin-bottom: 35px;
  background-color: lightgreen;
}
 
.second_para {
  color: red;
}
<body>
    <p class="para">
        Hello there.
    </p>
 
     
    <p class="para second_para">
        Same but in red.
    </p>
 
</body>
Winjas Force
  • 46
  • 1
  • 3