


Speaking of pseudo-selectors, I really realized how powerful CSS is. It’s so powerful that I don’t even seem to know CSS anymore. It’s a bit of a shock to us with some syntactic sugar in C# 6.0. . . First
We can preview it in VS in advance.
As you can see, there are many, many pseudo-classes above, so many that I am almost blind. . . Let’s talk about some of the more practical ones below.
1 :nth-child pseudo-selector
We know that there is a selector in jquery called "subclass selector", and the corresponding one is:nth-child , :first-child, :last-child, :only-child, this time it can also be done in CSS
, which can be said to relieve the pressure of jquery to a certain extent. Here is a simple example.
1 <html xmlns="http://www.w3.org/1999/xhtml"> 2 <head> 3 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 4 <title></title> 5 6 <style type="text/css"> 7 ul li:nth-child(1) { 8 color: red; 9 }10 </style>11 </head>12 <body>13 <ul>14 <li>1</li>15 <li>2</li>16 <li>3</li>17 <li>4</li>18 <li>5</li>19 <li>6</li>20 </ul>21 </body>
You can see that when I fill in :nth-child(1), the color of the first li of ul has changed. It’s red. If it’s more complicated, you can change 1 to n. When the browser parses the CSS pseudo-class
selector, it should internally call the corresponding method to parse the corresponding dom node. First of all, you must understand that n increases from 0 with a step size of 1. This is similar to jquery's nth-child. There is nothing
to say. Then let's try: first-child and last-child.
1 <html xmlns="http://www.w3.org/1999/xhtml"> 2 <head> 3 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 4 <title></title> 5 6 <style type="text/css"> 7 ul li:first-child { 8 color: red; 9 font-weight:800;10 }11 12 ul li:last-child {13 color: blue;14 font-weight: 800;15 }16 </style>17 </head>18 <body>19 <ul>20 <li>1</li>21 <li>2</li>22 <li>3</li>23 <li>4</li>24 <li>5</li>25 <li>6</li>26 </ul>27 </body>28 </html>
Two: checked, :unchecked,:disabled,:enabled
Also in jquery, There is a set of selectors called "form object properties", we can look at jquery's online documentation.
We are also very happy to find that these attributes also exist in css. . . Are you starting to get a little drunk? . . Still a sneak peek.
1. disabled,enabled
1 <!DOCTYPE html> 2 <html xmlns="http://www.w3.org/1999/xhtml"> 3 <head> 4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 5 <title></title> 6 7 <style type="text/css"> 8 input[type='text']:enabled { 9 border: 1px solid red;10 }11 12 input[type='text']:disabled {13 border: 1px solid blue;14 }15 </style>16 17 </head>18 <body>19 <form>20 <input type="text" disabled="disabled" />21 <input type="text"/>22 </form>23 </body>24 </html>
2. checked, unchecked
1 <!DOCTYPE html> 2 <html xmlns="http://www.w3.org/1999/xhtml"> 3 <head> 4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 5 <title></title> 6 7 <style type="text/css"> 8 form input[type="radio"]:first-child:checked { 9 margin-left: 205px;10 }11 </style>12 13 </head>14 <body>15 <form>16 <input class="test" type="radio" value="女" /><span>女</span><br/>17 <input class="test" type="radio" value="男" /><span>男</span>18 19 </form>20 </body>21 </html>
3. selected
Although this is not original in css, it can be replaced by option:checked, such as the following .
1 <!DOCTYPE html> 2 <html xmlns="http://www.w3.org/1999/xhtml"> 3 <head> 4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 5 <title></title> 6 7 <style type="text/css"> 8 option:checked { 9 color: red;10 }11 </style>12 13 </head>14 <body>15 <form>16 <select>17 <option>1</option>18 <option>2</option>19 <option>3</option>20 </select>21 </form>22 </body>23 </html>
Three empty pseudo-selectors
This selector is a bit interesting, it is called "content" in jquery "Selector" is used to find empty elements. If you play with jquery's empty, there is no problem with this.
Here is an example to change the background of the first empty p.
1 <!DOCTYPE html> 2 <html xmlns="http://www.w3.org/1999/xhtml"> 3 <head> 4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 5 <title></title> 6 7 <style type="text/css"> 8 9 p:first-child{10 width:500px;11 height:20px;12 }13 14 p:empty {15 background:red;16 }17 </style>18 19 </head>20 <body>21 <p></p>22 <p>他好</p>23 </body>24 </html>
Four: not(xxx) pseudo-selector
This is also a very classic not selector, called in jquery "Basic selector", do you remember it? ? ?
In general, when you read the above, do you feel that some "script processing behavior" has been integrated into CSS3? This feeling is that CSS is no longer the CSS you once knew.

The official account web page update cache, this thing is simple and simple, and it is complicated enough to drink a pot of it. You worked hard to update the official account article, but the user still opened the old version. Who can bear the taste? In this article, let’s take a look at the twists and turns behind this and how to solve this problem gracefully. After reading it, you can easily deal with various caching problems, allowing your users to always experience the freshest content. Let’s talk about the basics first. To put it bluntly, in order to improve access speed, the browser or server stores some static resources (such as pictures, CSS, JS) or page content. Next time you access it, you can directly retrieve it from the cache without having to download it again, and it is naturally fast. But this thing is also a double-edged sword. The new version is online,

The article discusses using HTML5 form validation attributes like required, pattern, min, max, and length limits to validate user input directly in the browser.

This article demonstrates efficient PNG border addition to webpages using CSS. It argues that CSS offers superior performance compared to JavaScript or libraries, detailing how to adjust border width, style, and color for subtle or prominent effect

Article discusses best practices for ensuring HTML5 cross-browser compatibility, focusing on feature detection, progressive enhancement, and testing methods.

The article discusses the HTML <datalist> element, which enhances forms by providing autocomplete suggestions, improving user experience and reducing errors.Character count: 159

The article discusses the HTML <meter> element, used for displaying scalar or fractional values within a range, and its common applications in web development. It differentiates <meter> from <progress> and ex

This article explains the HTML5 <time> element for semantic date/time representation. It emphasizes the importance of the datetime attribute for machine readability (ISO 8601 format) alongside human-readable text, boosting accessibilit

The article discusses the HTML <progress> element, its purpose, styling, and differences from the <meter> element. The main focus is on using <progress> for task completion and <meter> for stati


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

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

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

Dreamweaver Mac version
Visual web development tools

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

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft
