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?
You can apply multiple CSS property or value pairs for styling the element by separating each one with a semicolon within the style attribute.
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.
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.
.abc, .xyz { margin-left: 20px; }
is what you are looking for.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With