Can I specify multiple CSS classes with the same class name?

I have several CSS classes that I would like to specify for an element. But I do not want every time I repeat the place of 3, 4 or more classes.

I would like to go from

<span class ="class1 backgroundclass borderclass iconclass">Link</span>

For

<span class="linkClass">Link</span>

Can this be done? If so, how?

+3
source share
2 answers

In regular CSS, you need to include .linkClassin each class definition as follows:

.class1, .linkClass { ...... }
.backgroundclass, .linkClass { ...... }
.borderclass, .linkClass { ...... }

Not very good readability.

You can look at CSS preprocessors, such as LessCSS , that make this easier. Using LessCSS, you can do the following:

.linkClass {
  .class1;
  .backgroundclass;
  .borderclass;
}

LessCSS then compiles the final stylesheet.

+6
source

, , , .: -)

CSS, . , , CSS , .

, , , HTML, CSS. (..: , CSS.)

+2

Source: https://habr.com/ru/post/1758618/


All Articles