Three major selectors for CSS

Source: Internet
Author: User

Three major selectors
  1. Derived selectors, his grammatical features are: tag name {} 

    Next example

    body{

    babackground-image:url ("img/5.jpg");

    padding:0px; background-repeat:no-repeat;

    }

    This is the use of a simple background derivation selector, as you can see from this example that this style can only be used for body tags, and of course, The derived selector can also be used to see an example

    DL  dd{

     

      display:none;

      width:80px;

      height:30px;

     }

    Here's the meaning of the DD label within the DL style is this.  

  2. ID selector with syntax features: #id名称 {}

    We're looking at an example

    #logo {

      color:blue;

      font-style:inherit;

      font-size:60px

      width:100;

      height:60px;

     

     }

    Below is the reference ID selector

      <div id= "logo" ><center style= "font-size:50px;" > My web Design </center> </div>

    from this simple instance it is also easy to see that only the ID is the logo mark, in order to use the # The style of the logo

  3. Class selector, which is characterized by the following syntax:. Class Name {}

    Now let's look at a simple example.

    . back{

    Background-image:url ("img/5.jpg");

    padding:0px; " >background-repeat:no-repeat;

    }

    The following reference to the class selector

    <div class= "Back" ></div>

    The difference between the ID selector and the class selector can also be seen here, as long as the class selector is class= "back", which can refer to the class selector, that is, the ID selector can only be used in a tag, because the ID of each tag cannot be duplicated, but the class selector can be used in each tag.

  4. Look at the hybrid use of three selectors

    #menu DL dd{

    Display:none;

    width:80px;

    height:30px;

    }

    Next it's a reference

    <div id= "menu" >

    The ID selector and the derived selector are used here, which is the DD style within the tag div with the ID of menu as above.

    . Menu DL dd{

    Display:none;

    width:80px;

    height:30px;

    }

    Next it's a reference

    <div class= "Menu" >

    This is a mix of class selectors and derived selectors, that is, the DD style inside the tag div with the class name menu as above.

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.