HTML and CSS Basic courses (ix) CSS selectors

Source: Internet
Author: User

All HTML elements are selectors (all HTML elements are HTML)

The previous course defines the elements of

For example, set the background color for the entire body below

Body {  
     background-color: #C6E2FF;  
}

Multiple selectors (multiple selectors)

You can nest an HTML element inside another, for example,

<div>  
     <div>  
          <p>i like tacos!</p>

In this case, how does CSS give inside that inside of the <p> definition selector?

The method is as follows:

<span style= "font-size:14px" >div div p {  
     /*css stuff!*/  
}</span>

One selector to rule them all (global selector)

There is a very special selector that can be used to define all the elements of HTML: * Selector. For example:

* {  
     border:2px solid black;  
}

The black boundary of the entity will be set to 2 pixels for all elements.

Branching (branch)

You can think of an element of an HTML file as a tree (pictured above): The elements are branched from the root node

Parents, children, and siblings (father, son and brother)

If the

The nested selector above is set in this tree structure.

If the son of an element wants to apply a certain format, and does not want to let his son's son ... This format is also applied, so you can use the > symbol.

For example:

<div>  
    <div>  
         <p> </p>  
         <div>  <p> </div>  
    </div>  
</div>

You just want to get a format for the <p> in line 3rd, so you can:

div div > P {/  
    * some CSS setting*/  
}

Then the <p> on the inside will have no effect

Related Article

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.