Use the link tag to import external css style sheets<link rel="stylesheet" href="css/demo01 .css">
@import url("/crazy-html5/06css/css /demo01.css");
headAdd the
style tag to the head, and you can add the page style in the style tag.
<head> <style> table { background: #003366; } </style> </head>
table:{background:red; }
p[id]{background:red;}Represents a p element containing an id attribute
p[id=aaa]{background:red;} means it contains the id attribute, and the id =p element of aaa
p[id=^aaa]{background:red;}Indicates an element containing an id attribute, and the value of the id is a p element starting with aaa
p [id=$c]{background:red;} means that it contains the id attribute, and the value of id is a p element ending in c
#myp represents the element whose
id is
myp. The id selector must be preceded by Add the symbol
. must be added in front of the selector, such as
.myclass represents all elements whose
class value is
myclass.
p.important{color:red;}Elements that must meet both selector conditions can take effect.
h1 em{color:red}, this rule will Turn the text of the
em element that is a descendant of the
h1 element into red. Other
em text will not be affected by this rule.
h1>strong{color:red;} acts on the first-level
strong element in the
h1 element, and other levels are not affected
h1+p {margin-top:50px;}Select the paragraph that appears immediately after the h1 element. The h1 and p elements have the same parent element
h2,p{color:gray;}, will act on both the h2 element and the p element.
* is a wildcard selector that can match any element
:first-line{color:red;}Set a special style for the first line of text
:first-letter{color:red;}Set a special style for the first letter of text
:after, :beforeUnselector
:before{}Can be used to insert content in front of the element content, and the content is available
content is specified,
:after{} can be used to insert content after the element content, and the content can be specified with
content, such as
p:before{ content:url("img.png");}
after, before can be used with quotes,
quotes can be used with to set the quote type of nested quotes
<style> p>p { quotes: "《" "》" } p>p::before{ content: open-quote; } p>p::after{ content:close-quote; }</style>
after, before Use with the counter to add multi-level numbers in front of the text. This can be a special article, and I won’t go into details here.
:rootThe selector matches the document root element
:first-childSpecifies the style when the element is the first child of its parent
:last-childSpecifies the style when the element is the first child of its parent The style of the last child of the parent
Specifies the style when the element is the nth child of its parent
Matches the style when the element is an odd number of children of its parent
Matches when the element is an even-numbered child of its parent Style
Matches when the element is Its parent conforms to the style of the m*n+p child
Specifies when the element is its parent The style of the nth child from the last level
:hover
Style when the mouse pointer is on the element
:focus
The style of the element that receives focus
:enabled
The style of the enabled element
:disabled
The style of the disabled element
:checked
The style of the selected element (checkbox, radio )
::selection
The style of some elements selected by the user
:not(selector)
Select a style that is not this selector
##:targetSelect the currently active #news element, generally used with anchor points
The above is the detailed content of Detailed knowledge about css selector. For more information, please follow other related articles on the PHP Chinese website!