Detailed knowledge about css selector
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 sheet in the style sheet
@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>
- Ordinary tag selector
table:{background:red; } - #A tag containing a certain attribute
p[id]{background:red;}Represents a p element containing an id attribute
- A tag that contains an attribute and the attribute value is a specific value
p[id=aaa]{background:red;}means it contains the id attribute, and the id =p element of aaa
- An element that contains an attribute and the attribute value starts with a specific value
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
- An element containing a certain attribute and the attribute value ends with a specific value
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.
:root
The selector matches the document root element
:first-child
Specifies the style when the element is the first child of its parent
:last-child
Specifies the style when the element is the first child of its parent The style of the last child of the parent
- ##:nth-child(n)
Specifies the style when the element is the nth child of its parent
- odd
Matches the style when the element is an odd number of children of its parent
n is - even
Matches when the element is an even-numbered child of its parent Style
n is - m*n+p
Matches when the element is Its parent conforms to the style of the m*n+p child
- :nth-last-child(n)
Specifies when the element is its parent The style of the nth child from the last level
##:only-child - Specifies that it takes effect when the element is the only child element of its parent
- Specify the style of empty elements
- n is
Pseudo-class selector for element state
: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##:target
Select 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!

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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

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

Hot Topics

Using Bootstrap in Vue.js is divided into five steps: Install Bootstrap. Import Bootstrap in main.js. Use the Bootstrap component directly in the template. Optional: Custom style. Optional: Use plug-ins.

HTML defines the web structure, CSS is responsible for style and layout, and JavaScript gives dynamic interaction. The three perform their duties in web development and jointly build a colorful website.

WebdevelopmentreliesonHTML,CSS,andJavaScript:1)HTMLstructurescontent,2)CSSstylesit,and3)JavaScriptaddsinteractivity,formingthebasisofmodernwebexperiences.

There are two ways to create a Bootstrap split line: using the tag, which creates a horizontal split line. Use the CSS border property to create custom style split lines.

To set up the Bootstrap framework, you need to follow these steps: 1. Reference the Bootstrap file via CDN; 2. Download and host the file on your own server; 3. Include the Bootstrap file in HTML; 4. Compile Sass/Less as needed; 5. Import a custom file (optional). Once setup is complete, you can use Bootstrap's grid systems, components, and styles to create responsive websites and applications.

There are several ways to insert images in Bootstrap: insert images directly, using the HTML img tag. With the Bootstrap image component, you can provide responsive images and more styles. Set the image size, use the img-fluid class to make the image adaptable. Set the border, using the img-bordered class. Set the rounded corners and use the img-rounded class. Set the shadow, use the shadow class. Resize and position the image, using CSS style. Using the background image, use the background-image CSS property.

How to use the Bootstrap button? Introduce Bootstrap CSS to create button elements and add Bootstrap button class to add button text

To adjust the size of elements in Bootstrap, you can use the dimension class, which includes: adjusting width: .col-, .w-, .mw-adjust height: .h-, .min-h-, .max-h-
