CSS Common Selector

Source: Internet
Author: User

CSS Common selectors: Tag Selector, class selector, id selector, derivation selector, sub selector, combo selector

1: Tag Selector: If it is a declaration, you do not need a semicolon, and if you have multiple declarations, the last declaration does not require a semicolon

h1{color:red}
h1{color:red; font-size:14px}

2, class selector: In the CSS with a point beginning to represent the category selector definition, the name of all classes of selectors start with a point, after the period must start with a letter, the class name is allowed to use the word, number, hyphen "-" and underscore "_", class names case, class selector can be used alone, It can also be used in conjunction with other elements.

. important {color:red;}

*.important {color:red;}

Use with other elements

p.important {color:red;}

The selector now matches all p elements that have the class attribute containing important, but none of the other types of elements match, regardless of whether or not this class attribute is present.

3. ID selector: The ID selector can specify a specific style for HTML elements labeled with a specific ID. The ID selector is defined as "#".

#red {color:red;} #green {color:green;}

The ID selector can only be used once. ID selector and Derivation selector

#sidebar p {font-style:italic;text-align:right;margin-top:0.5em;}

The above style will only apply to paragraphs that appear in an element with an ID of sidebar. This ID selector can be used many times as a derived selector, even if the element labeled Sidebar only appears once in the document:

#sidebar p{font-style:italic; text-align:right; margin-top:0.5em;}   #sidebar h2{font-size:1em;font-weight:normal; font-style:italic; Margin:0;line-height:1.5;text-align:right;}

Defines the style for the label within the label. Derived inheritors

H1 strong{color:red;}

Change color only when <strong> appears in the

Child selector: Sub-selector (child selector) refers only to its immediate descendants

#links >a{Color:blue;}

The combo selector applies the same style to multiple elements, allowing multiple selectors to be combined, separating them with commas.

H1,H2,H3,H4 {color:red;}

This article from "Don't Make good" blog, reprint please contact the author!

CSS Common 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.