Using the :last-child Selector
Description
The :last-child
selector selects elements that are the last
elements defined by their parent element.
Example
The following code shows the :last-child
selector.
<!DOCTYPE HTML>
<html>
<head>
<style type="text/css">
:last-child {<!-- w w w. j av a2 s.c o m-->
border: thin black solid;
padding: 4px;
}
</style>
</head>
<body>
<a href="http://java2s.com">Visit the website</a>
<p>
I like <span>HTML</span> and <span>CSS</span>.
</p>
<a href="http://w3c.org">Visit the W3C website</a>
</body>
</html>
The body element is the last child of the html
element and is matched by the selector.