-
The selector
Version 1
The selector The sample instructions class .test{color: red} Select the tag class=”test” id #test{color:red} Select the label with ID =”test” element p{color: red} Select all p tags element, element div, p {} Select all divs and p’s offspring
element elementul li {border: 1px solid red; } choose ul
All of theli
Descendants (including sons and grandchildren…):link a:link {color: black; } Select all unvisited links :visited a:visited {color: red; } Select all visited links :hover a:hover {color: #fff} Mouse hover trigger :active a:active {background: yellow; } Select active link (hold mouse down without releasing trigger)
(Note: In the CSS definition, :active must come after :hover!):first-letter h1:first-letter{font-size: 200%} choose h1
In the first word:first-line p:first-line {background: yellow} Select each <p>
The first row of the elementVersion 2
The selector The sample instructions * * {padding: 0; } Select all labels Father and son element > element .list > li {border: 1px solid red; } choose class="list"
All the sons ofli
Brother element + element h1+p {color: red} in h1
Pick one in the backp
brotherattribute
[attribute][type] {display: block; } Choose to contain type
Attribute tagAttribute is equal to the
[attribute=value][type=text] {display: block; } choose type
Attribute values fortext
The label of theAttribute contains
[attribute~=value][eyes~= small eyes] {display:none} Select all the eyes
attributecontainsThe element of small eyes
(<span style =" max-width: 100%; clear: both; min-height: 1em;
)[attribute|=word] [eyes | = “small eyes”]
(often withattribute^=value
Confusion)choose eyes
Properties forSmall eyes
The opening element;
This value must be a full word (or be followed by a hyphen “- “)
Such as:Eyes = small eyes - Lee Young-ho
:focus input:focus{backgroundr:yellow; } Select the input element with focus The eldest son
element:first-childh1:first-child{color: red} Select a h1
The labelandIs the first element of its parent element
(h2:first-child
Not selected because H2 is the second son.):before span:before At the end of each <span>
Element before inserting content:after span:after At the end of each <span>
Insert content after the elementVersion 3
The selector The sample instructions The wine field brothers
element1~element2h1~p {color: red} Version 2 can only select one brother, version 3 can select one brother h1
Behind allp
brotherAttribute the beginning
[attribute^=value][name^=” li “]{border: 1px solid red; } Select all the name
Attribute to"Li"
The opening element,^
Similar to regularAttributes end
[attribute$=value]img[src$=”.png”]{width: 100%} choose src
for.png
At the end of theimg
The element
(Remember not to put a space after element.)Attribute contains
[attribute*=value][name * = “lee”]} {width: 100% Select all the name
Attribute contains"Li"
Initial element:first-of-type li:first-of-type{} Select all the li
andIs the first of its parent element:last-of-type li:last-of-type{} Select all the li
andIs the last of its parent element:only-of-type h2:only-of-type{} Select a h2
And it’s the only one
(h1:only-of-type
Not selected because not unique):only-child h2:only-child{} Select a h2
And is of its parent elementAn only child
Div1 had 4 so couldn’t pick himh2
):nth-child(n) div:nth-child(1){} Select a div
andIs the first child of its parent element:nth-last-child(n) div:nth-last-child(2){} Select a div
andIs the penultimate child of its parent element:nth-of-type(n) p:nth-of-type(2) Select that each p element is the second p element of its parent :nth-last-of-type(n) p:nth-last-of-type(2) The one that selects each p element is its parentThe bottomThe second p element The younger son
element:last-childh1:last-child choose h1
The labelandIs the last child of its parent element:root :root{background: red} Document root element pseudo-class :empty h1:empty{} Select an H1 tag with no child elements (empty tag) <h1></h1>
id:target #footer:target(:target) Select the anchor labels that are currently active (without id for all anchors) :not(selector) :not(p) Select elements that are not selector elements (that is, reverse select) ::selection ::selection{color: red} Selects the text selected by the cursor :enabled 【 mainly used with form elements 】
input[type=”text”]:enabledThe selector matches each enabled element :disabled 【 mainly used with form elements 】
input[type=”text”]:disabledThe selector matches each disabled element :checked 【 mainly used with form elements 】
input:checkedThe selector matches each selected input element
(Only applicable to radio buttons or check boxes):out-of-range 【 Mainly used for form verification 】
input:out-of-range{color: red; }Select the input outside of the set range. <input type="number" min="5" max="10" />
:in-range 【 Mainly used for form verification 】
input:in-range{color:green}Select the element whose input value is within the specified range :read-write 【 mainly used with form elements 】
input:read-write{border: 1px solid blue}Select the writable state input
:read-only 【 mainly used with form elements 】
input:read-only{background: gray; }Select the read-only state input
:optional 【 Mainly used for form verification 】
input:optional{border: 1px solid black}Select optional input
:required 【 Mainly used for form verification 】
input:required{border: 1px solid red}Select required input
<input required />
:valid 【 Mainly used for form verification 】
input:valid{color: green}Select the type of email [valid] input
<input type="email" />
:invalid 【 Mainly used for form verification 】
input:valid{border: 1px solid red}Select enter email [illegal] input
<input type="email" />
If there is any mistake, welcome to correct, thank you