CSS3 selector-moderate
Basic Selector
1. wildcard selector (*)-Support for all browsers
*{ marigin: 0; padding: 0; }
2. Element selector (E)-Support for all browsers
3. class selector (. className)-Support for all browsers
4. id selector (# ID)-Support for all browsers
5. Descendant selector (E F)-Support for all browsers
Select All EelementDescendant F elementIs a space in the middle;
6. Child element selector (E> F)-IE6 does not support
Select AllChild ElementF
7. Adjacent sibling element selector (E + F)-IE6 does not support
The EF element has the same parent element, and the F element is adjacent to the Eelement;
8. General brother selector (E ~ F)-IE6 does not support
Select All sibling elements after an element
9. Group selector1, selector2,..., selectorN)-Support for all browsers
Each selector is separated by a comma (,).
Attribute SelectorIE6 not supported
E [attr]: Only attribute names are used, but no attribute values are determined;
E [attr = "value"]: Specifies the attribute name and the attribute value;
E [attr ~ = "Value"]: Specifies the attribute name and has the attribute value. This attribute value is a word list separated by spaces. The word list contains a value word, and the "~" before the equal sign cannot be written;
E [attr = "value"] and E [attr ~ = "Value"]: When the attribute selector contains a wave (~), the attribute value matches when there is a value. If there is no wave (~), the attribute value matches only when it is completely a value.
E [attr ^ = "value"]: Specifies the attribute name and has a property value. The attribute value is a value.StartOf;
E [attr $ = "value"]: The property name is specified and has a property value. The property value is a value.EndOf;
E [attr * = "value"]: The property name is specified, and the property value is included;
E [attr | = "value"]: The attribute name is specified, and the attribute value is a value or a value starting with "value-" (for example, zh-cn );
Pseudo-class selector
1. Dynamic pseudo-classesFor: hover is supported by only a element in IE6,: active is not supported only by the IE6-7, And: focus is not supported in the IE6-7.
. Demo a: link {color: gray;}/* When the link is not accessed, the foreground color is gray */. demo a: visited {color: yellow;}/* after the link is accessed, the foreground color is yellow */. demo a: hover {color: green;}/* the foreground color is green when the mouse is suspended over the link */. demo a: active {color: blue;}/* click the link to activate the link. The foreground color is blue */
Attention sequence: LoVe/HAte, that is, Link -- visited -- hover -- active;
Also, focus is used for elements to become the focus, which is often used on form elements.
2. Pseudo-class UI element statusIE6-8 not supported
": Enabled", ": disabled", ": checked" is mainly used for Form Element operations in HTML.
input[type="text"]:disabled {border:1px solid #999;background-color: #fefefe;}
3. CSS3: nth Selector
: First-childSelect the first child element of an element;
: Last-childSelect the last child element of an element;
: Nth-child (n)Select one or more specific child elements for an element; the IE6-8 and FF3-browser do not support the ": nth-child" selector.
The n in the brackets can be integers, expressions, and keywords;
Integer: Starting from 1. For example, nth-child (3). Select the third child element under an element;
Expression: for example, 2n + 1, where n starts from 0. Here n can only be n and cannot be replaced by other letters;
Key words: odd, even;
: Nth-last-child ()Select one or more specific child elements of an element, and start from the last child element of the element;
: Nth-of-type ()Select the specified element;
: Nth-of-type is similar to: nth-child; the only difference is that this specifies the element type;
: Nth-last-of-type ()Select the specified Element and calculate it from the last element;
: First-of-typeSelect the first child element of the same type under a parent element;
: First-of-type and: last-of-type selectors are similar to: first-child and: last-child; the difference is that the element type is specified.
: Last-of-typeSelect the last child element of the same type as the parent element;
: Only-childThe selected element is the only element of its parent element;
": Only-child" indicates yesAn element is the only child element of its parent element.
: Only-of-typeSelect an element that is the only child element of the same type of its parent element;
: EmptyThe selected element does not contain any content.
: Empty is used to select elements without any content. Here, NO content indicates that there is no content at all, even a space;
3. Negative selector (: not)IE6-8 browser not supported
input:not([type="submit"]) {border: 1px solid red;}
4. pseudo elements
The two ":" and one ":" css3 are mainly used to distinguish between pseudo classes and pseudo elements. Up to now, both methods are accepted, that is to say, no matter which writing method is used, the function is the same, but a writing format is different.
: First-lineSelect the first line of the element, such as changing the text style of the first line of each paragraph;
: First-letterSelect the first letter of the text block, unless there are some other elements in the same line, but this is mainly used in paragraph layout, such as sinking the first word;
: Before AND: afterThese two are mainly used to insert content to the front or back of an element"Content"In combination, the most common thing we have ever seen is to clear the floating;
: SelectionUsed to change web browsingSelect the default effect for Chinese;
/* Webkit, Opera9.5 +, Ie9 + */: selection {background: color value; color: color value;}/* Mozilla Firefox */:: -moz-selection {background: color value; color: color value ;}
": Selection" can only set two attributes: background and color. setting other attributes does not work.
Refer:Http://www.w3cplus.com/css3/basic-selectors