CSS 选择器语法速查
Pseudo-classes
-
a:linkSelects all unvisited links
-
a:visitedSelects all visited links
-
a:hoverSelects links on mouse hover
-
a:activeSelects the active link element
-
p::afterInsert content after <p> element
-
p::beforeInsert content before <p> element
-
input:checkedSelects every checked <input> element
-
input:disabledSelects every disabled <input> element
-
p:emptySelects every <p> element with no children
-
input:enabledSelects every enabled <input> element
-
p:first-childSelects every <p> element that is the first child of its parent
-
p::first-letterSelects the first letter of every <p> element
-
p::first-lineSelects the first line of every <p> element
-
p:first-of-typeSelects every <p> element that is the first <p> element of its parent
-
input:focusSelects the <input> element which has focus
-
input:in-rangeSelects <input> elements with a value within a specified range
-
input:invalidSelects all <input> elements with an invalid value
-
p:lang(language)Selects all <p> elements with a lang attribute equal to ‘language’
-
p:last-childSelects every <p> element which is the last child of its parent
-
p:last-of-typeSelects every <p> element which is the last <p> element of its parent
-
:not(p)Selects every element that is not a <p>
-
p:nth-child(2)Selects every <p> element that is the second child of its parent
-
p:nth-last-child(2)Selects every <p> element that is the second child of its parent, counting from the last child
-
p:nth-last-of-type(2)Selects every <p> element that is the second <p> element of its parent, counting from the last child
-
p:nth-of-type(2)Selects every <p> element that is the second <p> element of its parent
-
p:only-of-typeSelects every <p> element that is the only <p> element of its parent
-
p:only-childSelects every <p> element that is the only child of its parent
-
input:optionalSelects <input> elements with no ‘required’ attribute
-
input:out-of-rangeSelects <input> elements with a value outside a specified range
-
input:read-onlySelects <input> elements with the ‘readonly’ attribute specified
-
input:read-writeSelects <input> elements with the ‘readonly’ attribute not specified
-
input:requiredSelects <input> elements with the ‘required’ attribute specified
-
:rootSelects the documents root element
-
::selectionSelects the portion of an element that is selected by a user
-
#id:targetSelects the current active #id element
-
input:validSelects all <input> elements with a valid value
Selectors
-
.classSelects all elements with .class
-
#idSelects all elements with #id
-
*Selects all elements
-
divSelects all <div> elements
-
div, pSelects all <div> and <p> elements
-
div > pSelects all <p> elements that are a direct descendant of a <div> element
-
div + pSelects all <p> elements that are the next sibling of (i.e. placed directly after) <div> elements
-
div ~ pSelects all <p> elements that follow, and are siblings of, <div> elements
Attributes
-
[attribute]Selects all elements with the specified attribute
-
[attribute=value]Selects all elements where the specified attribute is equal to ‘value’
-
[attribute~=value]Selects all elements with an attribute containing the word ‘value’
-
[attribute|=value]Selects all elements with an attribute list starting with ‘value’
-
[attribute^=value]Selects all elements with an attribute beginning with ‘value’
-
[attribute$=value]Selects all elements with an attribute ending with ‘value’
-
[attribute*=value]Selects all elements with an attribute containing the substring ‘value’
阅读余下内容