CSS3 basic selector
To better illustrate the problem, first create a simple DOM structure, as follows:
<div> <ul> <li>1</li> <li>2</li> <li>3</li> <li>4</li> <li>5</li> <li>6</li> <li>7</li> <li>8</li> <li>9</li> <li>10</li> </ul> </div>
1. Wildcard selector (*)
Wildcard selector is used to select all elements , you can also select all elements under a certain element. For example:
The code is as follows:
, the other is to select all elements under a certain element:
The code is as follows:
2. Element selector (E)
Element selector is css The most common and basic selector among selectors. Element selectors are actually elements of the document, such as html, body, p, div, etc. For example, in our demo: the elements include div, ul, li, etc.
The class selector specifies the style in a way that is independent of the document element. Before using the class selector, you need to define the class name on the html element. In other words, you need to ensure that the class name exists in the html tag so that the class can be selected, such as:
In "active, important, items", we add a class name to li so that the class selector can work normally and better associate the style of the class selector with the element.
.important {font-weight: bold; color: yellow;}
The above code means to add a "font-weight, color: yellow" style to the element with the important class name;
The class selector also It is possible to have multiple class names. As we saw above, there are two or more class names in our li element at the same time, and they are separated by spaces. Then the selector can also be connected together using multiple classes, such as:
.active {color: green;background: lime;}
.items {color: #fff;background: #000;}
.important.items { background:#ccc;}
.first.last {color: blue;}
The above means that all li elements in div.demo are selected
ul > li {background: green;color: yellow;}
The code above indicates that all sub-elements li under ul are selected. For example:
IE6 does not support child element selectors.
The above code means selecting the adjacent element li of li. We have a total of ten li here , then the above code selects from the 2nd li to the 10th li, a total of nine
.active ~ li {background: green;color: yellow; border: 1px solid #ccc;}
What the above code means is that all sibling elements li behind the li.active element are selected
9. Group selector (selector1, selector2,...,selectorN)
Group selector groups elements with the same style together. Each selector is separated by a comma ",", as above Shown are selector1,selector2,...,selectorN. This comma tells the browser that the rule contains multiple different selectors. If there is no this comma, the meaning expressed is completely different. Omitting the comma becomes the descendant selector we mentioned earlier. This is what everyone knows Be careful when using it.
For more detailed introduction to CSS selectors and related articles, please pay attention to the PHP Chinese website!

In this week's roundup: Firefox gains locksmith-like powers, Samsung's Galaxy Store starts supporting Progressive Web Apps, CSS Subgrid is shipping in Firefox

In this week's roundup: Internet Explorer finds its way into Edge, Google Search Console touts a new speed report, and Firefox gives Facebook's notification

You’re probably already at least a little familiar with CSS variables. If not, here’s a two-second overview: they are really called custom properties, you set

Building websites is programming. Writing HTML and CSS is programming. I am a programmer, and if you're here, reading CSS-Tricks, chances are you're a

Here's what I'd like you to know upfront: this is a hard problem. If you've landed here because you're hoping to be pointed at a tool you can run that tells

Picture-in-Picture made its first appearance on the web in the Safari browser with the release of macOS Sierra in 2016. It made it possible for a user to pop

Gatsby does a great job processing and handling images. For example, it helps you save time with image optimization because you don’t have to manually

I learned something about percentage-based (%) padding today that I had totally wrong in my head! I always thought that percentage padding was based on the


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

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Atom editor mac version download
The most popular open source editor

SublimeText3 Linux new version
SublimeText3 Linux latest version

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

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),