Css selector priority, css Selector

Source: Internet
Author: User

Css selector priority, css Selector
<Html>
<Head>
<Title> cascade feature </title>
<Style type = "text/css">
P {color: green}
. Red {color: red ;}
. Purple {color: purple ;}
# Line3 {color: blue ;}
</Style>
</Head>
<Body>
<P> This is the first line of text </p>
<P class = "red"> This is the second line of text </p>
<P id = "line3" class = "red"> This is the third line of text </p>
<P style = "color: orange;" id = "line3"> This is the fourth line of text. </p>
<P class = "purple red"> This is the fifth line of text </p>
</Body>
<Html>
Category Selection has a higher priority than the tag Selector
The ID selector is higher than the category selector.
The intra-row style has a higher priority than the category selector.
The preceding style has a higher priority than the latter
What is the priority of the CSS selector?

In this Code, the p tag first uses the. red style, and the second is the style defined by the p tag.
That is to say, if the style in the p label is the same as that in. red, the. red style will be used first. If the style of the p label is not in. red, the style is valid for the p label. That is, css inheritance, such as rewriting and writing code:
<Style type = "text/css">
. Red {font-size: 14px; color: red ;}
P {color: blue; font-size: 24px; text-decoration: underline}/* underline the p tag to see the effect */
</Style>

What is the priority of the CSS selector?

In this Code, the p tag first uses the. red style, and the second is the style defined by the p tag.
That is to say, if the style in the p label is the same as that in. red, the. red style will be used first. If the style of the p label is not in. red, the style is valid for the p label. That is, css inheritance, such as rewriting and writing code:
<Style type = "text/css">
. Red {font-size: 14px; color: red ;}
P {color: blue; font-size: 24px; text-decoration: underline}/* underline the p tag to see the effect */
</Style>

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.