Introduction to css selectors
Tag selector
For example:
`p`、`a`、`h[1,6]`、`span`、`div`、、、
Class selector(class)
class selector is defined with ".".
For example:
.id1{样式属性:值;}
Try not to use underscores in naming, as this may cause compatibility issues. Underscores are generally used in JS, and do not use pure numbers or Chinese names.
For example:
<div class="class1"></div>
Note:
The class selector also includes the multi-class name selector
<div class="class1 class2.."></div>
(Video tutorial recommendation: css video tutorial)
ID selector
id selector is defined with "#". For example: #id1{Style attribute: value;} naming method such as class selector
For example:
<div id="id1"></div>
Wildcard selector
*{样式属性:值;}
Pseudo-class selector
Link pseudo-class selector (mainly for a tag that can be absent but the order cannot be reversed)
:link /*未访问的链接*/:visited /*已访问的链接*/:hover /*鼠标移动到链接上*/ 最常用的链接伪类选择器:active /*选定的链接 别松开的状态*/
Structure (position) pseudo Class selector CSS3
:first-child Selects the specified selector that belongs to the first child element of its parent element
:last-child Selects the last child element that belongs to its parent element The specified selector
:nth-child(N) matches every element that is the Nth child element of its parent element, regardless of the element's type, counting from the last child element. N can be a number, keyword or formula
Keyword: odd is an odd number even is an even number
Expression: 2n even number 2n 1 odd number n is a multiple
:nth- last-child() is the number starting from the last child element. The default is the first element
target pseudo-class selector
:target target pseudo-class selector The selector can be used to select the currently active target element
Child element selector
The child element selector can only select elements that are child elements of an element.
Writing:
The parent comes first, the subset comes after, and the middle is connected with >
Note:> There must be a space on both sides, excluding grandchildren. Descendants set, only the son set does not use >, you can select all descendants
Attribute selector
The selector with certain special attributes can select the tag Use attribute selector
Writing: a[title] {} The attribute selector is represented by square brackets div[class^=font] { } div[class$=font] { } starting with font The ending div[class*=tao] { } means that tao can be in any position.
Pseudo-element selector (CSS3)
.dome Class selector: first-child Pseudo-class selector::first-letter Pseudo-element selector
E::first-letter The first word or character of the text
E::first-line The first line of the text
E::selection Can change the selected text Style (mouse)
E::before{ content: "Text" } Inside the box in front (add font)
E::after{ content: "Text" } Inside the box behind ( Add font)
Recommended tutorial: css quick start
The above is the detailed content of Introduction to css selectors. 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

AI Hentai Generator
Generate AI Hentai for free.

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

Setting the size of HTML text boxes is a very common operation in front-end development. This article explains how to set the size of a text box and provides specific code examples. In HTML, you can use CSS to set the size of a text box. The specific code is as follows: input[type="text"

How to adjust WordPress themes to avoid misaligned display requires specific code examples. As a powerful CMS system, WordPress is loved by many website developers and webmasters. However, when using WordPress to create a website, you often encounter the problem of theme misalignment, which affects the user experience and page beauty. Therefore, it is very important to properly adjust your WordPress theme to avoid misaligned display. This article will introduce how to adjust the theme through specific code examples.

In-depth understanding of the weight and priority of CSS selector wildcards In CSS style sheets, selectors are an important tool for specifying which HTML elements the style applies to. The selector's priority and weight determine which style is applied when multiple rules apply to an HTML element at the same time. Wildcard selectors are a common selector in CSS. It is represented by the "*" symbol, which means it matches all HTML elements. Wildcard selectors are simple but can be very useful in certain situations. However, the weight and precedence of wildcard selectors also

CSS selector priority is determined in the following order: Specificity (ID > Class > Type > Wildcard) Source order (Inline > Internal style sheet > External style sheet > User agent style sheet) Declaration order (latest declarations take precedence) Importance (!important forces the priority to increase)

Advanced selectors in CSS selectors include descendant selectors, child element selectors, adjacent sibling selectors, universal sibling selectors, attribute selectors, class selectors, ID selectors, pseudo-class selectors and pseudo-element selectors wait. Detailed introduction: 1. The descendant selector uses a space-separated selector to select the descendant elements of an element; 2. The child element selector uses a selector separated by a greater than sign to select the direct child elements of an element; 3. Adjacent sibling selectors use selectors separated by a plus sign to select the first sibling element immediately following an element, and so on.

The :not() selector can be used to exclude elements under certain conditions, and its syntax is :not(selector) {style rule}. Examples: :not(p) excludes all non-paragraph elements, li:not(.active) excludes inactive list items, :not(table) excludes non-table elements, div:not([data-role="primary"]) Exclude div elements with non-primary roles.

To master basic CSS selector syntax, specific code examples are required. CSS selectors are a very important part of front-end development. They can be used to select and modify various elements of HTML documents. Mastering basic CSS selector syntax is crucial to writing efficient stylesheets. This article will introduce some common CSS selectors and corresponding code examples. Element selector The element selector is the most basic selector, which can select the corresponding element by its tag name. For example, to select all paragraphs (p elements), you can use

Responsive Layout Framework Analysis: An Essential Guide from Beginners to Experts With the popularity and diversification of mobile devices, responsive layout has become an essential skill for modern web design. The responsive layout framework has become the preferred tool for developers due to its simplicity, flexibility and maintainability. However, for beginners, learning and understanding responsive layout frameworks can feel a little confusing. From beginner to expert, this article provides you with a detailed guide to mastering the responsive layout framework, along with concrete code examples. What is responsive cloth
