Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I apply styles to multiple classes at once?

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

.abc {     margin-left:20px;  }    .xyz {     margin-left:20px;  }
<a class="abc">Lorem</a>  <a class="xyz">Ipsum</a>

Since both classes are doing the same thing, I should be able to merge it into one. How can I do that?

like image 380
sat Avatar asked Jan 20 '10 05:01

sat


People also ask

How do I apply multiple styles in CSS?

You can apply multiple CSS property or value pairs for styling the element by separating each one with a semicolon within the style attribute.

How do you apply the same style to multiple elements?

When you group CSS selectors, you apply the same styles to several different elements without repeating the styles in your stylesheet. Instead of having two, three, or more CSS rules that do the same thing (set the color of something to red, for example), you use a single CSS rule that accomplishes the same thing.

Can CSS have multiple classes?

An element is usually only assigned one class. The corresponding CSS for that particular class defines the appearance properties for that class. However, we can also assign multiple classes to the same element in CSS. In some cases, assigning multiple classes makes page styling easier and much more flexible.


1 Answers

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

is what you are looking for.

like image 199
Juraj Blahunka Avatar answered Dec 03 '22 08:12

Juraj Blahunka