CSS-based CSS Selector

Source: Internet
Author: User


Example:

* [Lang = fr] {font-size: 14px; width: 120px ;}

*. Div {text-Decoration: none ;}

2. Type Selector
Syntax:

E {srules}

Note:
Type selector. Take the document language object (element) type as the selector.
Example:

TD {font-size: 14px; width: 120px ;}

A {text-Decoration: none ;}

3. Attribute Selector
Syntax:

E [ATTR] {srules}

E [ATTR = value] {srules}

E [ATTR ~ = Value] {srules}

E [ATTR | = value] {srules}

Note:
Attribute selector.
Select e with the ATTR attribute
Select e with the ATTR attribute and the attribute value is equal to the value
Select a word list with the ATTR attribute and the attribute value is separated by spaces. One of the words is equal to the value of E. The value here cannot contain spaces
Select a word list that has the ATTR attribute and the attribute value is separated by a hyphen.
Example:

H [title] {color: Blue ;}

/* All h objects with the title attribute */

SPAN [class = demo] {color: red ;}

Div [speed = "fast"] [dorun = "no"] {color: red ;}

A [rel ~ = "Copyright"] {color: black ;}

4. Include the selector
Syntax:

E1 E2 {srules}

Note:
Contains the selector. Select All E2 contained by E1. That is, e1.contains (E2) = true.
Example:

Table TD {font-size: 14px ;}

Div. sub A {font-size: 14px ;}

5. subobject Selector
Syntax:

E1> E2 {srules}

Note:
Sub-object selector. Select E2 for all E1 sub-objects.
Example:

Body> P {font-size: 14px ;}

/* The font size of all P objects as sub-objects of the body is 14px */

Div ul> li p {font-size: 14px ;}

6. ID Selector
Syntax:

# ID {srules}

Note:
Id selector. Take the ID of the object as the unique identifier in the document directory tree (DOM) as the selector.
Example:

# Note {font-size: 14px; width: 120px ;}

7. class selector
Syntax:

E. classname {srules}

Note:
Class selector. You can use this selector in HTML. The effect is equivalent to E [class ~ = Classname]. See attribute selectors ).
In ie5 +, you can specify more than one value for the class attribute (feature) of the object (classname) by specifying the class name of a group of style sheets separated by spaces. For example, <Div class = "class1 class2">.
Example:

Div. Note {font-size: 14px ;}

/* The font size of all Div objects whose class property values are equal to (including) "NOTE" is 14px */

. Dream {font-size: 14px ;}

/* The font size of all objects whose class property values are equal to (including) "NOTE" is 14px */

8. Select character groups
Syntax:

E1, E2, E3 {srules}

Note:
Character group. Apply the same definition to multiple delimiters. You can use commas to separate the delimiters and group them.
Example:

. TD1, Div A, body {font-size: 14px ;}

TD, Div, A {font-size: 14px ;}

9. Selection of pseudo classes and pseudo objects

Syntax:

E: pseudo-classes {srules}

E: pseudo-elements {srules}

Note:
Pseudo class and pseudo object selector.
Pseudo-class selector. See pseudo-classes (pseudo-classes) [: Link: hover: active: visited: focus: first-child: First: Left: Right: Lang].
Pseudo object selector. See pseudo object (pseudo-elements) [: First-letter: first-line: Before: After].
Example:

Div: First-letter {font-size: 14px ;}

A. Fly: hover {font-size: 14px; color: red ;}

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.