


What is a pseudo-class selector in css? A brief introduction to pseudo-class selectors
This chapter will tell you what is a pseudo-class selector in CSS? A brief introduction to pseudo-class selectors. Let everyone understand the role of pseudo-class selectors in css, what are the classifications of css pseudo-class selectors, and other knowledge. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you. (Related recommendations: "CSS Tutorial")
##1. Introduction to pseudo-class selectors
Pseudo-class selector (referred to as: pseudo-class) is defined by a colon, which defines the state of the element, such as click pressed, click completed, etc. The style can be modified for the state of the element through pseudo-classes. The function of the pseudo-class is similar to the element style in the general DOM, but unlike the element style in the general DOM, it does not change any DOM content. It just inserts some modified elements, which are visible to the user but not to the DOM. The effect of a pseudo class can be achieved by adding an actual class.What is a pseudo-class?It means that the css built-in class css itself gives it some features and functions, that is, you don’t need class=... or id=... You can use it directly. Of course, you can also change some of its attributes, such as: a:link{color:#FF0000;}
2. Pseudo-class selector The classification of
Pseudo-class selectors can be mainly divided into: dynamic pseudo-class selectors, UI element state pseudo-class selectors, structural pseudo-class selectors, and negative pseudo-class selectors. The selector syntax of these categories is introduced in detail below:1. Dynamic pseudo-class selector syntax
- E: link (link pseudo-class selector): Selects the matching E element, and the matching element is defined as a hyperlink and has not been visited. Commonly used on link description points
- E:visited (link pseudo-class selector): Selects the matching E element, and the matching element is defined with a hyperlink and has been visited. Commonly used on link drawing points
- E:active (user behavior selector): Select the matching E element, and the matching element is activated. Commonly used on link strokes and buttons
- E:hover (user behavior selector): Select the matching E element, and the user's mouse stays on the element E. IE6 and below browsers only support a:hover
- E:focus (user behavior selector): Select the matching E element, and the matching element gets focus
- :link "Link": Before the hyperlink was clicked
- :visited "Visited": After the link was visited
- :hover "Hover": When the mouse is placed on the label
- :active "Activate": When the mouse clicks on the label but does not let go.
/*让超链接点击之前是红色*/ a:link {color: red;} /*让超链接点击之后是橙色*/ a:visited {color: orange;} /*鼠标悬停,放到标签上的时候是绿色*/ a:hover {color: green;} /*鼠标点击链接,但是不松手的时候*/ a:active {color: black;}a tag. The order between each style is very particular. Once it appears, Arrangement errors are likely to cause overwriting, causing one of the styles to be unable to be displayed. So how do these four pseudo-class selectors of the a tag need to be sorted before they can be used? In the CSS definition, a:hover must be placed after a:link and a:visited to be effective, and a:active must be placed after a:hover to be effective. So, the order of the four pseudo-class selectors of the a tag is: a:link, a:visited, a:hover, a:active
2.UI elements Status pseudo-class selector
- E:checked (selected status pseudo-class selector): Matches the selected check button or radio button form element
- E:enabled (enabled status pseudo-class selector): matches all enabled form elements
- E:disabled (unavailable status pseudo-class selector): matches All disabled form elements
input[type="text"]:disabled {border:1px solid #999;background-color: #fefefe;}Note: IE6-8 does not support ":checked", ":enabled", ":disabled" are the three selectors.
3. Structural pseudo-class selector
- E: fisrt-child: The element E that is the first child element of the parent element. Equivalent to E:nth-child(1)
E:last-child :作为父元素的最后一个子元素的元素E。与E:nth-last-child(1)等同
E:root:选择匹配元素E所在文档的根元素。在HTML文档中,根元素始终是html,此时该选择器与html类型选择器匹配的内容相同
E F:nth-child(n):选择父元素E的第n个子元素F。其中n可以是整数(1,2,3)、关键字(even,odd)、可以是公式(2n+1),而且n值起始值为1,而不是0.
E F:nth-last-child(n):选择父元素E的倒数第n个子元素F。此选择器与E:nth-child(n)选择器计算顺序刚好相反,但使用方法都是一样的,其中:nth-last-child(1)始终匹配最后一个元素,与last-child等同
E:nth-of-type(n) :选择父元素内具有指定类型的第n个E元素
E:nth-last-of-type(n):选择父元素内具有指定类型的倒数第n个E元素
E:first-of-type:选择父元素内具有指定类型的第一个E元素,与E:nth-of-type(1)等同
E:last-of-tye :选择父元素内具有指定类型的最后一个E元素,与E:nth-last-of-type(1)等同
E:only-child :选择父元素只包含一个子元素,且该子元素匹配E元素
E:only-of-type:选择父元素只包含一个同类型子元素,且该子元素匹配E元素
E:empty: 选择没有子元素的元素,而且该元素也不包含任何文本节点
结构伪类选择器,可以根据元素在文档中所处的位置,来动态选择元素,从而减少HTML文档对ID或类的依赖,有助于保持代码干净整洁。
结构伪类选择器很容易遭到误解,需要特别强调。如:
p:first-child;
它表示的是:选择父元素下的第一个子元素 p,而不是选择 p 元素的第一个子元素。
注意:
结构伪类选择器中,子元素的序号是从 1 开始的,也就是说,第一个子元素的序号是 1,而不是 0。换句话说,当参数 n 的计算结果为 0 时,将不选择任何元素。
4.否定伪类选择器
E:not(F):匹配所有除元素F外的E元素
例:对form中所有input加边框,但又不想submit也起变化,就可以这样写:
input:not([type="submit"]) {border: 1px solid red;}
The above is the detailed content of What is a pseudo-class selector in css? A brief introduction to pseudo-class selectors. For more information, please follow other related articles on the PHP Chinese website!

What does it look like to refactor your own code? John Rhea picks apart an old CSS animation he wrote and walks through the thought process of optimizing it.

CSSanimationsarenotinherentlyhardbutrequirepracticeandunderstandingofCSSpropertiesandtimingfunctions.1)Startwithsimpleanimationslikescalingabuttononhoverusingkeyframes.2)Useeasingfunctionslikecubic-bezierfornaturaleffects,suchasabounceanimation.3)For

@keyframesispopularduetoitsversatilityandpowerincreatingsmoothCSSanimations.Keytricksinclude:1)Definingsmoothtransitionsbetweenstates,2)Animatingmultiplepropertiessimultaneously,3)Usingvendorprefixesforbrowsercompatibility,4)CombiningwithJavaScriptfo

CSSCountersareusedtomanageautomaticnumberinginwebdesigns.1)Theycanbeusedfortablesofcontents,listitems,andcustomnumbering.2)Advancedusesincludenestednumberingsystems.3)Challengesincludebrowsercompatibilityandperformanceissues.4)Creativeusesinvolvecust

Using scroll shadows, especially for mobile devices, is a subtle bit of UX that Chris has covered before. Geoff covered a newer approach that uses the animation-timeline property. Here’s yet another way.

Let’s run through a quick refresher. Image maps date all the way back to HTML 3.2, where, first, server-side maps and then client-side maps defined clickable regions over an image using map and area elements.

The State of Devs survey is now open to participation, and unlike previous surveys it covers everything except code: career, workplace, but also health, hobbies, and more.

CSS Grid is a powerful tool for creating complex, responsive web layouts. It simplifies design, improves accessibility, and offers more control than older methods.


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

Dreamweaver Mac version
Visual web development tools

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

SublimeText3 Chinese version
Chinese version, very easy to use

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.

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
