CSS/Selectors/pseudo-classes/:last-child

From W3C Wiki
< CSS‎ | Selectors
Revision as of 20:49, 26 September 2011 by Hiroki (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Pseudo-class :last-child

The :last-child pseudo-class represents an element that is the last child of some other element. Same as :nth-last-child(1).

Syntax

selector:last-child{ properties }


Example

The following selector represents a list item li that is the last child of an ordered list ol:

[style.css]

 ol > li:last-child{
   color: red;
 }


[index.html]

<body>
  <ol>
    <li>List-item 1</li>
    <li>List-item 2</li>
    <li>List-item 3</li>
  </ol>
</body>

Css3 selectors last-child.png

CSS defines the :last-child pseudo-class selector in 6.6.5.7. :last-child pseudo-class.