Methods to import external css style sheets
Use the link tag to import external css style sheets
<link rel="stylesheet" href="css/demo01.css">
Import (import) external style sheets in the style sheet
@import url("/crazy-html5/06css/css/demo01.css");
Use internal style sheet
The internal style sheet can only be applied to a certain web page. The definition method is to add the style tag in the head header. You can add it in the style tag. Page style.
<head> <style> table { background: #003366; } </style> </head>
Selector knowledge points
Element attribute selector
1) Ordinary tag selector
table:{background:red;}
2) A tag containing a certain attribute
p[id]{background:red;} represents a p element containing an id attribute
3) A tag that contains an attribute and the attribute value is a specific value
p[id=aaa]{background:red;} represents a p element that contains the id attribute and id=aaa
4) Elements that contain an attribute and the attribute value starts with a specific value
p[id=^aaa]{background:red;} means that it contains an id attribute, and the id value starts with aaa p element
5) An element that contains an attribute and the attribute value ends with a specific value
p[id=$c]{background:red;} means that it contains the id attribute, and the id The value is a p element ending in c
ID selector
id selector, specifying the element whose id is a specific value, for example, #myp means that the id is myp For elements with a value, the symbol
#Class selector must be added in front of the id selector. The class selector is an element that matches the class value. The symbol must be added in front of the selector. , for example, .myclass represents all elements whose class value is myclass.
Class selectors can be used in conjunction with element selectors. For example, p.important{color:red;} must meet the conditions of both selectors to take effect.Contains selectors and descendant selectors
The descendant selector can select elements that are descendants of an element, for example: 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.
Child selector
is similar to the descendant selector, but will only act on certain direct descendants of the element. For example, h1>strong{color:red;} acts on the first-level strong element in the h1 element, and other levels are not affected
Adjacent sibling selector
If you need to select an element immediately after another element, and both have the same parent element, you can use the adjacent sibling selector, such as h1+p{margin-top:50px;} to select the element immediately after h1 In the paragraph that appears, h1 and p elements have the same parent element
Selector grouping
Selectors that act on multiple elements at the same time, such as h2, p{color :gray;} will affect both the h2 element and the p element.
* is a wildcard selector that can match any elementPseudo element selector
1): first-line{color:red; }Set a special style for the first line of text
2):first-letter{color:red;}Set a special style for the first letter of text:after, :before no selector:before{} can be used to insert content in front of the element content. The content can be specified by content. :after{} can be used to insert content after the element content. The content can be specified by content, such asp:before{ content:url("img.png"); }
after and before can be used with quotes, quotes can be used with the quotation mark type for setting nested references
<style> p>p { quotes: "《" "》" } p>p::before{ content: open-quote; } p>p::after{ content:close-quote; } </style>after, before can be used with counters
You can use a counter to add multi-level numbers in front of the text. This can be a special article and will not be detailed here.
Pseudo-class selector
1 :root selector matches the document root element
2 :first-child specifies when the element is its parent The style of the first child3 :last-child specifies the style of the last child when the element is its parent4 :nth-child(n) specifies the style when the element is The style of the nth child of its parent When n is odd, it matches when the element is an odd-numbered child of its parent When n is even, it matches when the element is an even number of its parent The style of the child When n is m*n+p, match the style of the element whose parent conforms to the m*n+pth child5 :nth-last-child (n) Specifies the style that takes effect when the element is the n-th child from the last of its parent6 :only-child specifies the style that takes effect when the element is the only child element of its parent7 :empty Specify the style of empty elementsPseudo-class selector for element status
1 :hover Style when the mouse pointer is on the element
2 :focus Style of the element that gets focus3 :enabledStyle of the enabled element4 :disabledStyle of the disabled element5 :checkedStyle of the selected element( checkbox,radio)6 ::selection The style of some elements selected by the user7 :not(selector) selects a style that is not this selector8 :target selection The currently active #news element, generally used with anchor pointsThe above is the detailed content of Detailed explanation of several common CSS selector examples. For more information, please follow other related articles on the PHP Chinese website!

GooFonts is a side project signed by a developer-wife and a designer-husband, both of them big fans of typography. We’ve been tagging Google

Pavithra Kodmad asked people for recommendations on what they thought were some of the most timeless articles about web development that have changed their

Learning how to build GraphQL APIs can be quite challenging. But you can learn how to use GraphQL APIs in 10 minutes! And it so happens I've got the perfect

When a component lives in an environment where the data queries populating it live nearby, there is a pretty direct line between the visual component and the

Here's some legit CSS trickery from yuanchuan. There is this CSS property offset-path. Once upon a time, it was called motion-path and then it was renamed. I

Miriam Suzanne explains in a Mozilla Developer video on the subject.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SublimeText3 Chinese version
Chinese version, very easy to use

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function