Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding more than one class html [duplicate]

Tags:

html

class

Is it possible to add more than one class in html? Here is what i've tried:

<a href="#" class="class1" class="class2">My Text</a>

Thanks! :)

like image 701
Stefan Avatar asked Jul 14 '15 17:07

Stefan


People also ask

Can we add multiple classes in HTML?

HTML elements can be assigned multiple classes by listing the classes in the class attribute, with a blank space to separate them.

Can class be repeated in HTML?

Yes, it is possible, but you can only declare the class attribute once per HTML element. Just separate the classes you want to apply by a space. If you declare the class attribute more than once, all definitions beyond the first will be ignored, so in your code .

Can a div have 2 classes?

Absolutely, divs can have more than one class and with some Bootstrap components you'll often need to have multiple classes for them to function as you want them to. Applying multiple classes of course is possible outside of bootstrap as well. All you have to do is separate each class with a space.

Can HTML element have multiple ids?

The HTML id attribute is used to specify a unique id for an HTML element. You cannot have more than one element with the same id in an HTML document.


1 Answers

Yes, it is possible, but you can only declare the class attribute once per HTML element. Just separate the classes you want to apply by a space.

<a href="#" class="class1 class2">My Text</a>

If you declare the class attribute more than once, all definitions beyond the first will be ignored, so in your code .class2 will not be applied to your link.

like image 66
connexo Avatar answered Oct 04 '22 23:10

connexo