Detailed explanation of examples of selectors in CSS3
English original text: www.456bereastreet.com/archive/200601/css_3_selectors_explained/
Chinese translation: www.dudo.org/article.asp?id=197
Note: This article was written in January 2006, when IE7, IE8 and Firefox3 had not yet been released. All the browser support mentioned in the article did not include these three versions of browsers. Use in IE8 and Fir
:nth-of-type()
:nth-of-type() pseudo-class and nth-child() pseudo-class The method is very similar, except that it matches elements of the type specified in the rule. The following rule will match every p element that belongs to the third child element of the parent element (there may be many p elements belonging to the third child element in one, but they are located under different parent elements, dudo note):
p:nth-of-type(3) { background:#ff0; }
This method is useful when you want to determine whether the third p element has been pointed to. At first you may think that this has the same effect as using nth-child, but nth-child(3) will count all child elements, so the result may be different, unless all sibling elements of p are also p element.
:nth-of-type pseudo-class is currently not supported by browsers.
:nth-last-of-type pseudo-class
: The element pointed to by the nth-last-of-type pseudo-class has several elements of the same type after it. Like the :nth-last-child pseudo-class, it counts backwards from the last child element. The following rules will match the penultimate sibling element p (note: it is a sibling and node of the same level):
p:nth-last-of-type(2) { background:#ff0 ; }
:nth-last-of-type() is currently not supported by browsers.
:last-child pseudo-class
:last pseudo-class points to the last child element in the parent element. It has the same effect as :nth-last-child(1). The following rule matches all p that is the last child element in the parent element:
p:last-child { background:#ff0; }
:last-child The pseudo-class can be used in Mozilla-based used in the browser. Opera does not support the :last-childe pseudo-class, and there is a bug in Safri (the above rule will match all p elements). Surprisingly it works fine in OmniWeb (beta version 5.1.1), even though this browser is based on Safari. This may be due to the return of the latest version of Apple's WebKit, as OmniWeb typically uses a slightly lower version of WebKit than Safari.
:first-of-type pseudo-class
:first-of-type pseudo-class points to the first element among elements of the same type. It is the same as :nth-of-type(1).
p:first-of-type { background:#ff0; }
: The first-of-type pseudo-class is currently not supported by browsers.
:last-of-type pseudo-class
:last-of-type pseudo-class points to the last element among elements of the same type. It is the same as nth-last-of-type(1).
p:last-of-type { background:#ff0; }
:last-of-type pseudo-class is currently not supported by browsers.
:only-child pseudo-class
:The only-childe pseudo-class points to elements that do not have any other child elements in their parent elements. It is the same as :first-child:last-child or :nth-child(1):nth-last-child(1) (the latter is not professional and concise enough).
p:only-child { backgound:#ff0; }
:only-childe pseudo-class is currently available in Mozilla-based browsers. In Safari it seems to be interpreted as: first-child (the above rule will be matched to all first child elements p in the document).
:only-of-type pseudo-class
:only-of-type pseudo-class points to those parent elements that no longer have child elements of the same type. This is the same as :first-of-type:last-of-type or :nth-of-type(1):nth-last-of-type(1) (the latter is not professional enough).
p:only-of-type { background:#ff0; }
:only-of-type pseudo-class is currently not supported by browsers.
【Related recommendations】
2. Integrate 20 common CSS/CSS3 properties
3. h5 and css3 to create an input box with prompt text
4. Share several commonly used latest css3 attributes
5. Use CSS to create small sharp corners and bubble effects of the chat box
The above is the detailed content of Detailed explanation of examples of selectors in CSS3. For more information, please follow other related articles on the PHP Chinese website!

In this post, Blackle Mori shows you a few of the hacks found while trying to push the limits of Cohost’s HTML support. Use these if you dare, lest you too get labelled a CSS criminal.

Custom cursors with CSS are great, but we can take things to the next level with JavaScript. Using JavaScript, we can transition between cursor states, place dynamic text within the cursor, apply complex animations, and apply filters.

Interactive CSS animations with elements ricocheting off each other seem more plausible in 2025. While it’s unnecessary to implement Pong in CSS, the increasing flexibility and power of CSS reinforce Lee's suspicion that one day it will be a

Tips and tricks on utilizing the CSS backdrop-filter property to style user interfaces. You’ll learn how to layer backdrop filters among multiple elements, and integrate them with other CSS graphical effects to create elaborate designs.

Well, it turns out that SVG's built-in animation features were never deprecated as planned. Sure, CSS and JavaScript are more than capable of carrying the load, but it's good to know that SMIL is not dead in the water as previously

Yay, let's jump for text-wrap: pretty landing in Safari Technology Preview! But beware that it's different from how it works in Chromium browsers.

This CSS-Tricks update highlights significant progress in the Almanac, recent podcast appearances, a new CSS counters guide, and the addition of several new authors contributing valuable content.

Most of the time, people showcase Tailwind's @apply feature with one of Tailwind's single-property utilities (which changes a single CSS declaration). When showcased this way, @apply doesn't sound promising at all. So obvio


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

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

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

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

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

Dreamweaver Mac version
Visual web development tools
