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!

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

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

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

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

Hot Topics











The browser's unresponsive method after the WebSocket server returns 401. When using Netty to develop a WebSocket server, you often encounter the need to verify the token. �...

The steps to register an Ouyi account are as follows: 1. Prepare a valid email or mobile phone number and stabilize the network. 2. Visit Ouyi’s official website. 3. Enter the registration page. 4. Select email or mobile phone number to register and fill in the information. 5. Obtain and fill in the verification code. 6. Agree to the user agreement. 7. Complete registration and log in, carry out KYC and set up security measures.

To safely download the Binance APP, you need to go through the official channels: 1. Visit the Binance official website, 2. Find and click the APP download portal, 3. Choose to scan the QR code, app store, or directly download the APK file to download to ensure that the link and developer information are authentic, and enable two-factor verification to protect the security of the account.

Discussion on the reasons why JavaScript cannot obtain user computer hardware information In daily programming, many developers will be curious about why JavaScript cannot be directly obtained...

Generating a WeChat applet QR code with parameters in Java and displaying it on an HTML page is a common requirement. This article will discuss in detail how to use J...

Confusion and answers about JWT and Session Many beginners are often confused about their nature and applicable scenarios when learning JWT and Session. This article will revolve around J...

After the USDT transfer address is incorrect, first confirm that the transfer has occurred, and then take measures according to the error type. 1. Confirm the transfer: view the transaction history, obtain and query the transaction hash value on the blockchain browser. 2. Take measures: If the address does not exist, wait for the funds to be returned or contact customer service; if it is an invalid address, contact customer service and seek professional help; if it is transferred to someone else, try to contact the payee or seek legal help.

The Ouyi Exchange app supports downloading of Apple mobile phones, visit the official website, click the "Apple Mobile" option, obtain and install it in the App Store, register or log in to conduct cryptocurrency trading.
