CSS Series (7) CSS Class selector class detailed

Source: Internet
Author: User
Tags set background

This article is written in notes form.

1, CSS class selector detailed

Http://www.w3school.com.cn/css/css_selector_class.asp

Knowledge Points:

(1) The premise of using class selector is to add a class attribute to the tag, such as <p class= "important" ></p>

(2) The syntax of the class selector is: *.important {color:red;}, but generally omits the preceding wildcard selector, written as. important {color:red;}, which adds a style to all tags with class= "important".

(3) Apply a style to a tag with a class, such as P.important {color:red;} This will only match elements labeled P and class= "important".

(4) Set multiple classes for a label, and the styles of these classes will be applied to the label. Like what:

<p class= "Important Warning" >

This paragraph is a very important warning.

</p>

P tags also have the class important and warning, no points around.

Styles are:

. important {Font-weight:bold;} Set to Bold

. warning {font-style:italic;} Set to italic

This paragraph p will be both bold and italic.

(5) Two classes are written together, without order, will match the elements containing two classes, such as:

. important.warning {background:silver;} Set Background to Silver

This selector matches elements that have both class important and warning.

(6) 4th and 5th are the so-called "multi-Class selectors", which says that in previous versions of IE7, Internet Explorer on different platforms could not handle multi-class selectors correctly.

However, I have tested on IE6, 7 and 8, and there is no problem.

2, the difference between class selector classes and ID selectors

Http://www.w3school.com.cn/css/css_selector_id.asp

Knowledge Points:

(1) The ID selector can only be used once in the document

You can search for the article "Why the ID of an HTML tag must be unique"

(2) The list of ID words cannot be used, i.e. it cannot be like a multi-class selector. Red.bold can choose a label that has both a class red and a bold, #red #bold this is not allowed.

(3) ID can contain more meanings, such as id= "Mostimportant" represents "most important", which is unique, and class= "important" stands for "important", there may be many.

CSS Series (7) CSS Class selector class detailed

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.