Home  >  Article  >  Web Front-end  >  How to Select the Second Last Element with CSS?

How to Select the Second Last Element with CSS?

Linda Hamilton
Linda HamiltonOriginal
2024-11-06 13:54:02739browse

How to Select the Second Last Element with CSS?

Selecting the Second Last Element with CSS

When using :last-child, you can only select the last element in a group. However, if you need to select the second last element, you can utilize the :nth-last-child(2) selector in CSS3.

This selector would select the DIV element with the text "SELECT THIS":

<code class="html"><div id="container">
  <div>a</div>
  <div>b</div>
  <div>SELECT THIS</div> <!-- THIS -->
  <div>c</div>
</div></code>

Browser Support

:nth-last-child has wide browser support, including:

  • Chrome 2
  • Firefox 3.5
  • Opera 9.5, 10
  • Safari 3.1, 4
  • Internet Explorer 9

The above is the detailed content of How to Select the Second Last Element with CSS?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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