Home Web Front-end CSS Tutorial Several commonly used selectors in CSS3

Several commonly used selectors in CSS3

Nov 24, 2017 pm 01:19 PM
css3 Selector

After the birth of HTML in the early 1990s, CSS was born at the end of 1996. CSS is specifically designed to define the basic attributes of web pages. So in CSS3, what are the commonly used selectors? Let me introduce it to you today.

The birth of HTML in the early 1990s

At the end of 1996, the first version of CSS was born

May 1998 CSS2 was officially released

2004 CSS2 .1 Release

Release of CSS3 2002 2003 2004 2005 2007 2009 2010

Modular development

CSS1 defines the basic attributes of the web page:

font , color, Basic selector, etc.

CSS2 adds advanced functions based on CSS1

floating and positioning, advanced selector, etc. (sub-selector, relative Neighbor selector, Universal selector)

CSS3 follows modular development. The release time is not a point in time, but a period of time.

Universal selector: * Select all elements

Select child elements:> Select direct descendants of elements

Adjacent sibling selectors: + Selects the first element immediately after the target element

Ordinary sibling selector: ~ Selects all sibling elements immediately following it

:nth-child Selects the specified index Child element at

nth-child(n) nth child element under parent element

nth-child(odd) odd-numbered child element

nth-child(even ) Even child element

:nth-last-child(n) The nth child element from the bottom

:nth-of-type(n) The nth child of the specified type under the parent element Element

:nth-last-of-type The penultimate n-th child element of the specified type under the parent element

:first-child Selects the first child element under the parent element

:last-child selects the last child element under the parent element

:only-child selects the only child element under the parent element

:only-of-type selects the parent element The only child element of the specified type under

:root selects the root directory of the document and returns the html

E[attr] attribute name, not sure about the specific attribute value

E[attr ="value"] specifies the attribute name, and specifies its corresponding attribute value

E[attr ~="value"] specifies the attribute name, which has multiple attribute values ​​separated by spaces and contains the value

E[attr ^= "value"] specifies the attribute name, the attribute value starts with value

E[attr $="value"] specifies the attribute name, and the attribute value ends with value

E[attr *="value"] specifies the attribute name, and the attribute value contains value

E[attr |= "value"] specifies the attribute name, and the attribute value starts with value-

UI PseudoClass selector

:enabled Select the enabled state element

:disabled Select the disabled state element

:checked Select the selected one Input elements (radio buttons or check boxes)

:default Select the default element

:valid, invalid Select valid or invalid input elements based on input validation

: in-range, out-of-range Select elements within or outside the specified range

:repuired, optional Select input elements based on whether the required attribute is allowed or not

Dynamic Pseudo-class selector :

:link selects the link element

:visited selects the element that the user can access

:hover selects the element on which the mouse is hovering

:ative The event triggered when the mouse clicks

:focus The element currently receiving focus

Other pseudo-class selectors:

:not() Negate the selection of the bracketed selector

:lang() Element based on langglobal attribute

:target url fragment The element pointed to by the identifier

:emptySelect the element whose content is empty

:selection The mouse cursor selects the element content

That’s it for the selectors of CSS3, more exciting Please pay attention to other related articles on php Chinese website!


Related reading:

What new background attributes are there in CSS3

How to use CSS3 Media Inquiries

How to make a flexible box in css3

The above is the detailed content of Several commonly used selectors in CSS3. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1660
14
PHP Tutorial
1261
29
C# Tutorial
1234
24
How to implement lace borders in css3 How to implement lace borders in css3 Sep 16, 2022 pm 07:11 PM

In CSS, you can use the border-image attribute to achieve a lace border. The border-image attribute can use images to create borders, that is, add a background image to the border. You only need to specify the background image as a lace style; the syntax "border-image: url (image path) offsets the image border width inward. Whether outset is repeated;".

Use the :nth-child(n+3) pseudo-class selector to select the style of child elements whose position is greater than or equal to 3 Use the :nth-child(n+3) pseudo-class selector to select the style of child elements whose position is greater than or equal to 3 Nov 20, 2023 am 11:20 AM

Use the :nth-child(n+3) pseudo-class selector to select the style of child elements whose position is greater than or equal to 3. The specific code example is as follows: HTML code: <divid="container"><divclass="item"&gt ;First child element</div><divclass="item"&

What is the identifier of the id selector in css What is the identifier of the id selector in css Sep 22, 2022 pm 03:57 PM

In CSS, the identifier of the id selector is "#". You can specify a specific style for the HTML element marked with a specific id attribute value. The syntax structure is "#ID value {attribute: attribute value;}". The ID attribute is unique and non-repeatable in the entire page; the ID attribute value should not start with a number. IDs starting with numbers will not work in Mozilla/Firefox browsers.

What to do if the javascript selector fails What to do if the javascript selector fails Feb 10, 2023 am 10:15 AM

The JavaScript selector fails because the code is not standardized. The solution is: 1. Remove the imported JS code and the ID selector method will be effective; 2. Just introduce the specified JS code before introducing "jquery.js".

Learn new CSS features: Directional clipping overflow:clip Learn new CSS features: Directional clipping overflow:clip Oct 11, 2022 pm 07:12 PM

This article will introduce a new feature, starting from Chrome 90, a new feature added to overflow - overflow: clip. Use it to easily control the overflow direction.

Do selectors in css include hypertext tag selectors? Do selectors in css include hypertext tag selectors? Sep 01, 2022 pm 05:25 PM

Not included. CSS selectors include: 1. Tag selector, which locates specific HTML elements through the element name of the HTML page; 2. Class selector, which locates specific HTML elements through the value of the class attribute of the HTML element; 3. ID selector, which Locate specific HTML elements through the value of the id attribute of the HTML element; 4. The wildcard selector "*" can refer to all types of tag elements, including custom elements; 5. The attribute selector uses the existing attribute name of the HTML element or attribute value to locate a specific HTML element.

Learn about the selectors supported by lxml in one article Learn about the selectors supported by lxml in one article Jan 13, 2024 pm 02:08 PM

lxml is a powerful Python library for processing XML and HTML documents. As a parsing tool, it provides a variety of selectors to help users easily extract the required data from documents. This article will introduce the selectors supported by lxml in detail. lxml supports the following selectors: Tag selector (ElementTagSelector): Select elements by tag name. For example, select elements with a specific tag name by using <tagname>

Detailed explanation of using SVG to add logo to favicon Detailed explanation of using SVG to add logo to favicon Sep 07, 2022 am 10:30 AM

How to add logo to favicon using SVG? The following article will introduce to you how to use SVG to generate favicon with logo. I hope it will be helpful to you!

See all articles