"If a worker wants to do his job well, he must first sharpen his tools." - Confucius, "The Analects of Confucius. Lu Linggong"
Front page > Programming > Why Doesn\'t `p.visible:last-of-type` Target the Last Visible Paragraph Element?

Why Doesn\'t `p.visible:last-of-type` Target the Last Visible Paragraph Element?

Published on 2024-11-16
Browse:767

Why Doesn\'t `p.visible:last-of-type` Target the Last Visible Paragraph Element?

:last-of-type Selector Behavior

The :last-of-type pseudo-class targets the last element of a specified type within a parent container. However, in the context of your CSS selector (p.visible:last-of-type), it's important to note that :last-of-type solely applies to element types and not class instances.

In your HTML markup:

This should be hidden

This should be displayed

This should be hidden

The issue arises because :last-of-type targets the last

element, which in this case does not have the .visible class. Consequently, none of your

elements are visible.

Solution

To target the last

element with the .visible class, you must use JavaScript, as there is no built-in CSS selector for this specific purpose.

Latest tutorial More>

Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.

Copyright© 2022 湘ICP备2022001581号-3