HTML/CSS Selector Priority

Source: Internet
Author: User

CSS Selector Precedence

1、同级样式默认后者覆盖前者2、样式优先级类型(1)  <  class[type](10)=伪类(10)  <  id(100)  <  style行间样式(1000) < style内部样式 < link外部引入样式选择符的对应值综合相加起来大的优先级高注 : 对应值只是代表他们的等级,    11个类型选择符的优先级仍然小于1个类选择符,以此类推3、important(IE7及以上)    加了important的样式属性优先级最高。    例
        .box{background:red!important;}

Testing: Interpreting the priority of AB
A, #header #div1. box1 Div. section p. link{.........}
B, #some. Base #font #call a{..........}

方法一:A= 100+100+10+1+10+1+10 = 232B= 100+10+100+100+1 = 311 B>A 方法二:AB每人干掉2个id选择符,A没有id选择符了,B还有一个,所以B优先级高答案:B

Copyright NOTICE: This article for Bo Master original article, reprint also please message.

HTML/CSS Selector Priority

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.