CSS Advanced Syntax

Source: Internet
Author: User

Grouping of selectors

You can group selectors so that the grouped selectors can share the same claims. Separate the selectors that need to be grouped with commas. In the following example, we group all the header elements. All the caption elements are green.

h1,h2,h3,h4,h5,h6{  color:green;  }
Inheritance and its problems

Depending on the CSS, child elements inherit attributes from the parent element. But it doesn't always work this way. Take a look at the following rule:

Body {     Font-family:verdana, sans-serif;     }

According to the above rule, the BODY element of the site will use the Verdana font (if the font exists in the visitor's system).

With CSS inheritance, child elements inherit the attributes owned by the highest-level elements (in this case, the body) (these child elements such as P, TD, UL, OL, UL, Li, DL, DT, and DD). No additional rules are required, and all child elements of the body should display the Verdana font, as are the child elements of the child element. And in most modern browsers, it is true.

But that is not necessarily the case in the bloody era of browser wars, when support for standards is not a business priority. For example, Netscape 4 does not support inheritance, it ignores inheritance, and also ignores rules applied to the BODY element. Ie/windows until IE6 there is a related problem, the font style inside the table is ignored. What are we supposed to be doing?

Treat Netscape with Kindness 4

Fortunately, you can deal with the Legacy browser's inability to understand inheritance by using the redundancy rules we call "be Kind to Netscape 4".

Body  {     font-family:verdana, sans-serif;     } P, TD, UL, OL, Li, DL, DT, DD  {     font-family:verdana, sans-serif;     }

4.0 browsers do not understand inheritance, but they can understand group selectors. This will waste some of the user's bandwidth, but if you need to support Netscape 4 users, you have to.

Is inheritance a curse?

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. No problem. Create a special rule for P so that 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;     }

CSS Advanced Syntax

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.