Get the App
SLTechnology News&Howtos  ›  Development  › 

How css groups selectors and declares them

Shulou Source: shulou.com Published: 2022-06-01 05:32:57 10月03日 Update

This article mainly introduces css how to group selectors and declare grouping, which is very detailed and has a certain reference value. Friends who are interested must read it!

We can group selectors as well as declarations.

Suppose you want all H2 elements to have a red background and display as blue text using a 28-pixel high Verdana font, you can write the following style:

H2 {font: 28px Verdana;} h2 {color: blue;} h2 {background: red;}

But the above approach is not efficient. It can be troublesome especially when we create such a list for an element with multiple styles. Instead, we can group the declarations together:

H2 {font: 28px Verdana; color: white; background: black;}

This is exactly the same as the previous three-line stylesheet.

Note that for declaration grouping, it is important to use a semicolon at the end of each declaration. The browser ignores spaces in the stylesheet. As long as you add a semicolon, you have no scruples about creating styles in the following format:

H2 {font: 28px Verdana; color: blue; background: red;} above is all the content of the article "how css groups selectors and declares groups". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Tags: Grouping style selection elements content semicolons articles same important no scruples values practices pixels interests multiple fonts guys buddies effects efficiency Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft NVidia vpn Docker Apple