Home > Web Front-end > CSS Tutorial > How Can I Reliably Style the Last List Item in All Browsers?

How Can I Reliably Style the Last List Item in All Browsers?

Patricia Arquette
Release: 2024-11-29 07:23:09
Original
694 people have browsed it

How Can I Reliably Style the Last List Item in All Browsers?

Using the Last-Child Selector

When attempting to target the final li element within a specific ul, one might naturally consider employing the :last-child selector. However, it is important to note that this pseudo-class has limited browser support, particularly in older versions of Internet Explorer and Safari.

In such instances, a reliable alternative is to explicitly designate the last li using a dedicated class, such as last-child. This allows you to target it specifically with CSS:

li.last-child {
    border-bottom: 1px solid #b5b5b5;
}
Copy after login

This approach ensures cross-browser compatibility and effectively highlights the last li, as intended.

The above is the detailed content of How Can I Reliably Style the Last List Item in All Browsers?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template