css-derivation Selector

Source: Internet
Author: User
Tags define

Derivation Selector
In CSS1, selectors that apply rules in this way are called contextual selectors (contextual selectors) because they rely on context to apply or avoid a rule. In CSS2, they are called derivation selectors, but they work the same regardless of what you call them.
The derivation selector allows you to determine the style of a label based on the contextual relationship of the document. By using the derivation selector rationally, we can make the HTML code cleaner.
For example, if you want the strong element in the list to become italic rather than the usual bold word, you can define a derivation selector:
Li Strong {
Font-style:italic;
Font-weight:normal;
}
Example:
I'm bold, not italic, because I'm not in the list, so this rule doesn't work for me.
I am the italic character. This is because the strong element is inside the LI element.
I am the normal font.
In the example above, only the strong element in the LI element is styled in italics, and the code is more concise without having to define a particular class or ID for the strong element.
Then look at the following CSS rules:
Strong {
color:red;
}
H2 {
color:red;
}
H2 Strong {
Color:blue;
}
The following is the HTML that it exerts effect on, as follows:
The strongly emphasized word in this paragraph isred.
This subhead is also red.
The strongly emphasized word in this subhead isblue.



Related Article

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.