CSS Selector :last-child

Description

The :last-child selector selects the last child element.

Example


<!DOCTYPE HTML> 
<html> 
    <head> 
        <style type="text/css"> 
        :last-child { <!--from w w  w .j  a  v  a  2  s . c  o  m-->
            border: thin black solid; 
            padding: 4px; 
        } 
        </style> 
    </head> 
    <body> 
        <p>I like <span>HTML</span> and <span>CSS</span>.</p> 
        <a href="http://java2s.com">Visit java2s.com</a> 
    </body> 
</html>

Click to view the demo

The body element is the last child of the html element and is matched by the selector.

The code above generates the following result.

:last-child




















Home »
  HTML CSS »
    HTML CSS Reference »




HTML Tag Reference
CSS Reference
CSS Selector Reference
Encoding Reference