Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Example analysis of CSS selector and declaration

2025-04-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces the example analysis of CSS selector and declaration, which has a certain reference value, and interested friends can refer to it. I hope you will gain a lot after reading this article.

Grouping of CSS selectors

Selectors are grouped, and the grouped selectors share the same declaration. Separate the selectors that need to be grouped with commas.

In the following example, all the title elements are grouped. All the title elements are green.

H2,h3,h4,h5,h6,h7 {color: green;}

CSS inheritance

Body {font-family: Verdana, sans-serif;}

Inheritance and its problems

In CSS, child elements inherit attributes from parent elements. The body element of the site will use the Verdana font (provided the font exists on the user's system).

With CSS inheritance, child elements inherit the attributes owned by the highest-level element, without the need for additional rules.

All child elements of body (such as p, td, ul, ol, ul, li, dl, dt, and dd) will display Verdana fonts, as will child elements of child elements.

However, not all browsers work in this way, and we can use the "redundancy rule" to deal with the problem that old browsers cannot understand inheritance.

Redundancy rule

Body {font-family: Verdana, sans-serif;} p, td, ul, ol, li, dl, dt, dd {font-family: Verdana, sans-serif;}

Child elements uninherit

What if you don't want the "Verdana, sans-serif" font to be inherited by all the child elements?

For example, you want the font of the paragraph to be Times. Then, create a separate rule for p, and it will get rid of the rules of the parent element:

Body {font-family: Verdana, sans-serif;} td, ul, ol, ul, li, dl, dt, dd {font-family: Verdana, sans-serif;} p {font-family: Times, "Times New Roman", serif } Thank you for reading this article carefully. I hope the article "sample Analysis of CSS selectors and statements" shared by the editor will be helpful to you. At the same time, I also hope that you will support us and follow the industry information channel. More related knowledge is waiting for you to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report