This article brings you knowledge about in-depth understanding of CSS pseudo-class selectors (code examples). It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.
Preface
In the past, I have sporadically understood and used pseudo-classes such as :link
, ::after
and content
, Pseudo-element selector. I found something lacking in this aspect when I was reading a book recently, so I decided to study it a little more in-depth. The following is a summary of the pseudo-class part.
Pseudo-class
Pseudo-class selectors essentially allow designers to set different visual effects based on the specific state of the element. Specifically, they are :link
, :visited
, :hover
, :active
, :focus
, :focus-within
, :target
, :root
, and :checked
. The four classic pseudo-classes of
HTMLAnchorElement
##:link
, used to set the style of the initial state of the link;
:visited
, used to set the style after the link is clicked;
:hover
, used to set the style of the link when the mouse is hovering over the link;
:active
, used to set the style of the link when the mouse button is pressed but not released , the style of the link.
LVAH) by heart, haha.
#) to the end of the URL is called the hash or fragment of the URL, which is used to locate a certain resource within the page. Assume that the page now has the element
Target
, then as long as
#title is entered in the address bar, the browser will continue to scroll (scrolling will not stop) There must be a tween animation) until the element
h3#title is located at a specific position in the visual area. (Note: Please do not confuse it with UI Routing)
The above-mentioned positioned page resource is called target element or currently active element! Its style can be set via :target
.
Compatibility: Supported by IE9. Example:
// 当前URL为http://foo.com#1 :target { color: red; } .title{ color: blue; &:target{ border: solid 1px red; } } .title{I'm not target element.} .title#1{Yes, I'm.}Set the style when the element gets focus
:focus is used to set the style when the element is in focus.
Compatibility: IE8 starts to support.
So which elements support the focus state? Then you need to first figure out what operations can be used to achieve focus.
They are:
- Mouse click;
- Tab key;
- Pass JavaScript's
HTMLElement.prototype.focus()
method.
a,
button,
input,
select and
textareas.
In HTML5, when the element is set with the
contenteditable or
tabindex attribute, the element supports the focus state.
That is, elements that match the following selectors support the focus state.
a,button,input,select,textarea,[contenteditable],[tabindex]Note: If the
tabindex attribute value is less than 0, the focus cannot be obtained through the Tab key. But the element can gain focus via mouse click or script.
/*
* 加载完成时默认返回body
* 若某元素获得焦点时,则返回该元素
*/
document.activeElement :: HTMLElement
There is also a misleading attribute
// 用于检测文档是否得到焦点,即用户是否正在与页面交互 // 页面仅仅位于屏幕可视区域,而用户没有与之交互时返回false。 document.hasFocus :: Void -> BooleanSet the style of the element when the child element gets focus
:focus-within, used to set the style of the element when the child element is in focus.
Compatibility: Chrome63 starts to support.
.form-control{ &:focus-within > input{ &:focus { border: solid 1px skyblue; } &:not(:focus){ border: solid 1px orange; } } } .form-control>input.pwd[type=password]+input.confirm-pwd[type=password]Others
:root
, used for setting
The style of the element is supported starting from IE9.
:checked
, used to set the selected style of radio and check controls, supported starting from IE9. Combined with the pseudo-element
::beforeand
contentattributes, flexible and efficient custom radio and check controls can be realized.
:empty
, used to set the style of elements without child nodes.
p{ }is an element with TEXT_NODE child node, while
p{}is an element with no child node.
:not
, as a predicate expressing the semantics of negation.
:placeholder-shown
, used to set the style when the element placeholder is displayed.
About CSS pseudo-class selection Device_html/css_WEB-ITnose
The above is the detailed content of In-depth understanding of CSS pseudo-class selectors (code examples). For more information, please follow other related articles on the PHP Chinese website!

Here's a container with some child elements:

Flyout menus! The second you need to implement a menu that uses a hover event to display more menu items, you're in tricky territory. For one, they should

"The power of the Web is in its universality. Access by everyone regardless of disability is an essential aspect."- Tim Berners-Lee

In this week's roundup: datepickers are giving keyboard users headaches, a new web component compiler that helps fight FOUC, we finally get our hands on styling list item markers, and four steps to getting webmentions on your site.

The short answer: flex-shrink and flex-basis are probably what you’re lookin’ for.

In this week's look around the world of web platform news, Google Search Console makes it easier to view crawled markup, we learn that custom properties

The IndieWeb is a thing! They've got a conference coming up and everything. The New Yorker is even writing about it:


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

SublimeText3 Linux new version
SublimeText3 Linux latest version

Dreamweaver Mac version
Visual web development tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

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