Get the App
SLTechnology News&Howtos  ›  Development  › 

How to group selectors in HTML

Shulou Source: shulou.com Published: 2022-06-01 05:08:28 09月12日 Update

This article focuses on "how to group selectors in HTML". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Now let the editor take you to learn how to group selectors in HTML.

A grouping selector for all elements in the document. With the wildcard selector, you can specify the color attribute value of all elements in the document as red with just one keystroke (only one asterisk).

Declaration grouping

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;} at this point, I believe you have a better understanding of "how to group selectors in HTML". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Tags: Grouping selection style element content semicolon document learning practical deeper same important no scruples practices pixels interests just multiple fonts practicality Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux Redmi Shulou Technology Microsoft Huawei