:last-of-type - HTML CSS CSS Selector

HTML CSS examples for CSS Selector:last-of-type

Description

The :last-of-type selector selects element that is the last child of a particular type inside its parent.

It is the same as :nth-last-of-type(1).

Example

Select the last <p> element of its parent:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<head>
<style>
p:last-of-type {<!--   w  ww .ja  v a 2s .c o m-->
    background: #ff0000;
}
</style>
</head>
<body>

<h1>This is a heading</h1>
<p>The first paragraph.</p>
<p>The second paragraph.</p>
<p>The third paragraph.</p>
<p>The fourth paragraph.</p>

<div>
<h1>This is a heading</h1>
<p>The first paragraph.</p>
<p>The second paragraph.</p>
<p>The third paragraph.</p>
<p>The fourth paragraph.</p>
</div>

</body>
</html>

Related Tutorials