CSS tutorial: in-depth analysis of CSS selector grouping
This article mainly introduces the relevant information of CSS selector grouping. Friends who need it can refer to it
Selector grouping
## Suppose you want both the h2 element and the paragraph to be gray. To achieve this, the easiest thing to do is to use the following declaration:h2, p {color:gray;}
body, h2, p, table, th, td, pre, strong, em {color:gray;}
/* no grouping */ h1 {color:blue;} h2 {color:blue;} h3 {color:blue;} h4 {color:blue;} h5 {color:blue;} h6 {color:blue;} /* grouping */ h1, h2, h3, h4, h5, h6 {color:blue;}
/* group 1 */ h1 {color:silver; background:white;} h2 {color:silver; background:gray;} h3 {color:white; background:gray;} h4 {color:silver; background:white;} b {color:gray; background:white;} /* group 2 */ h1, h2, h4 {color:silver;} h2, h3 {background:gray;} h1, h4, b {background:white;} h3 {color:white;} b {color:gray;} /* group 3 */ h1, h4 {color:silver; background:white;} h2 {color:silver;} h3 {color:white;} h2, h3 {background:gray;} b {color:gray; background:white;}
Wildcard Selector
CSS2 introduces a new simple selector - the universal selector, which is displayed as an asterisk (*). This selector can match any element, just like a wildcard. For example, the following rule can make every element in the document red:* {color:red;} <html> <head> <style type="text/css"> * {color:red;} </style> </head> <body> <h1>这是 heading 1</h1> <h2>这是 heading 2</h2> <h3>这是 heading 3</h3> <h4>这是 heading 4</h4> <p>这是一段<b>普通</b>的段落文本。</p> </body> </html>
Declaration Grouping
We can group both selectors and declarations. Suppose you want all h1 elements to have a red background and display blue text using the 28-pixel-high Verdana font, you can write the following style:h1 {font: 28px Verdana;} h1 {color: blue;} h1 {background: red;}
h1 {font: 28px Verdana; color: white; background: black;}
h1 { font: 28px Verdana; color: blue; background: red; }
h1 { font: 28px Verdana; color: blue background: red; }
Combining selector and declaration grouping
We can combine selector grouping and declaration grouping in one rule, and we can use few statements to define relatively complex style. The following rule specifies a complex style for all headings:h1, h2, h3, h4, h5, h6 { color:gray; background: white; padding: 10px; border: 1px solid black; font-family: Verdana; } <html> <head> <style type="text/css"> h1, h2, h3, h4, h5, h6 { color:gray; background: white; padding: 10px; border: 1px solid black; font-family: Verdana; } </style> </head> <body> <h1>This is heading 1</h1> <h2>This is heading 2</h2> <h3>This is heading 3</h3> <h4>This is heading 4</h4> <h5>This is heading 5</h5> <h6>This is heading 6</h6> </body> </html>
Combining selectors and declared grouping
We can By combining selector grouping and declaration grouping in rules, relatively complex styles can be defined with very few statements. The following rule specifies a complex style for all headings:h1, h2, h3, h4, h5, h6 { color:gray; background: white; padding: 10px; border: 1px solid black; font-family: Verdana; }
Combining selector and declaration grouping
We can combine selector grouping and declaration grouping in one rule, and we can use few statements to define relatively complex style. The following rule specifies a complex style for all headings:h1, h2, h3, h4, h5, h6 { color:gray; background: white; padding: 10px; border: 1px solid black; font-family: Verdana; }
The above is the detailed content of CSS tutorial: in-depth analysis of CSS selector grouping. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Using Bootstrap in Vue.js is divided into five steps: Install Bootstrap. Import Bootstrap in main.js. Use the Bootstrap component directly in the template. Optional: Custom style. Optional: Use plug-ins.

HTML defines the web structure, CSS is responsible for style and layout, and JavaScript gives dynamic interaction. The three perform their duties in web development and jointly build a colorful website.

There are two ways to create a Bootstrap split line: using the tag, which creates a horizontal split line. Use the CSS border property to create custom style split lines.

WebdevelopmentreliesonHTML,CSS,andJavaScript:1)HTMLstructurescontent,2)CSSstylesit,and3)JavaScriptaddsinteractivity,formingthebasisofmodernwebexperiences.

To set up the Bootstrap framework, you need to follow these steps: 1. Reference the Bootstrap file via CDN; 2. Download and host the file on your own server; 3. Include the Bootstrap file in HTML; 4. Compile Sass/Less as needed; 5. Import a custom file (optional). Once setup is complete, you can use Bootstrap's grid systems, components, and styles to create responsive websites and applications.

To adjust the size of elements in Bootstrap, you can use the dimension class, which includes: adjusting width: .col-, .w-, .mw-adjust height: .h-, .min-h-, .max-h-

How to use the Bootstrap button? Introduce Bootstrap CSS to create button elements and add Bootstrap button class to add button text

There are several ways to insert images in Bootstrap: insert images directly, using the HTML img tag. With the Bootstrap image component, you can provide responsive images and more styles. Set the image size, use the img-fluid class to make the image adaptable. Set the border, using the img-bordered class. Set the rounded corners and use the img-rounded class. Set the shadow, use the shadow class. Resize and position the image, using CSS style. Using the background image, use the background-image CSS property.
