Combining Styles for Multiple Classes
In CSS, it's often desirable to apply the same style properties to multiple elements with different class names. This eliminates the need for repetitive code.
Consider the following code, where two classes, .abc and .xyz, have the same margin-left property:
<code class="css">.abc { margin-left: 20px; } .xyz { margin-left: 20px; }</code>
To combine these styles into a single rule, use a comma-separated list of class names. The resulting rule will apply the same properties to both .abc and .xyz:
<code class="css">.abc, .xyz { margin-left: 20px; }</code>
This combined rule allows you to control the margin-left property for both .abc and .xyz elements, reducing code redundancy and improving maintainability.
The above is the detailed content of How to Combine Styles for Multiple Classes in CSS?. For more information, please follow other related articles on the PHP Chinese website!