CSS selector priority

Source: Internet
Author: User

-- 1 --

Style = "color: Orange")> ID selector (name)> class selector> label selector (P)

Multiple category selectors. The former prevails. (Class = "purple red") Purple

[The more special the style (the more targeted), the higher the priority]

 

-- 2 --

CSS writing

Generally, only the class or ID is defined for the outer mark.

The inner layer tag is nested,

When the sub-tag cannot use this rule, it is declared separately,

Eg: ul Li {...} can set an ID or class for a li

 

P span {color: Blue} tags for all descendants

P> span {color: Blue} for child tags

 

Set CSS using inheritance features

Eg: ul Li {color: Green}

 

-- 3 --

Cascade: a solution with multiple selectors setting for a single attribute = conflict

Inheritance: According to the HTML structure, CSS is set from the parent to the child, and the child inherits all styles from the parent. You can also modify the style of the child itself (without affecting the parent)

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.