Home  >  Article  >  Web Front-end  >  How to Combine Multiple CSS Class Styles without Repeating Code?

How to Combine Multiple CSS Class Styles without Repeating Code?

Mary-Kate Olsen
Mary-Kate OlsenOriginal
2024-10-28 11:54:58636browse

How to Combine Multiple CSS Class Styles without Repeating Code?

Combining Multiple CSS Class Styles

To apply the same CSS property to multiple classes without repeating code, consider merging the class selector declarations. This can be achieved by separating the class names with a comma, as seen below:

<code class="css">.abc, .xyz {
  margin-left: 20px;
}</code>

In this example, the CSS property margin-left: 20px; is applied to both the .abc and .xyz classes. The CSS snippet in your example can be rewritten using this approach:

<code class="css">.abc {
  margin-left: 20px;
}

.xyz {
  margin-left: 20px;
}</code>

Becomes:

<code class="css">.abc, .xyz {
  margin-left: 20px;
}</code>

The above is the detailed content of How to Combine Multiple CSS Class Styles without Repeating Code?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn