CSS (selector)

Source: Internet
Author: User

Grammar
 
   
  
  1. <style type="text/css>
  2. </style>
Tag Selector
 
   
  
  1. li {
  2. color: red;
  3. }

   ID Selector
 
   
  
  1. #li{
  2. color: yellow;
  3. }
Unique, the same page can only have one
Higher precedence than Class selector
class Selector
 
   
  
  1. .li{
  2. color: blue;
  3. }

Higher precedence than the tag Selector Universal Selector  Lowest priority level
 
    
  
  1. *{
  2. }
Descendant Selector
 
    
  
  1. div li{
  2. color:red;
  3. }
> Descendant Selector, you can only select the next level of class or tag, not leapfrog
 
     
  
  1. div>ul>li{
  2. color:red;
  3. }
Intersection Selector
 
     
  
  1. .li#li{
  2. /*
  3. 元素必须同时满足.li和#li才能使用
  4. */
  5. }
and set Selector
 
     
  
  1. .li,#li,div{
  2. /*
  3. 元素只要具备一个条件即可生效
  4. */
  5. }

   CSS3 New SelectorSelector Priority 1. First principle: Near-priority, the most inner selector is always preferable to the outer layer
Example: Div ul li >div #ul, Li in the UL inner layer, so the Li tag Selector can overwrite the outer ID selector
2. When acting on the same layer, the ID selector >class Selector > tag Selector
Example: Div #li >div. Li>div Li
3. As used for the same layer, and the last layer selector does not have a precedence relationship (both class or ID)
Example: Div ul Li >div Li, the scope of the selection of more accurate, then higher priority
4. When the precedence is identical, the following selectors overwrite the previous selector in the Order of code execution


Null

CSS (selector)

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.