Style failure caused by CSS priority selection, css priority Style

Source: Internet
Author: User

Style failure caused by CSS priority selection, css priority Style

Style invalidation caused by the priority of the separator:

Because the CSS selection operator priority may cause some styles to fail, this problem may be encountered by beginners, but it is often not easy to find.

Code example:

<! DOCTYPE html> 

The above code sets all text in the li element to green. At this time, the requirement may change. To use the first li element as the title, you need to change its element.
The Code is as follows:

<! DOCTYPE html> 

Although the class is set separately for the first li element and the new color is specified, it does not take effect. This is caused by the priority of the selector.

You only need to modify the CSS Code as follows:

.mydiv li{color:green;}  .mydiv .myli{color:blue;}

For details about the priority rules of selector, refer to the section CSS selector Priority 1.

Original address: http://www.51texiao.cn/div_cssjiaocheng/2015/0519/1894.html

The original address is: http://www.softwhy.com/forum.php? Mod = viewthread & tid = 4701.

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.