:only-of-type - HTML CSS CSS Selector

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

Description

The :only-of-type selector selects element that is the only child of its type within its parent.

Example

Select <p> element that is the only child of its type, of its parent:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<head>
<style>
p:only-of-type {<!-- w ww .jav a 2 s  . c om-->
    background: red;
}
</style>
</head>
<body>

<div><p>This is a paragraph.</p></div>

<div><p>This is a paragraph.</p><p>This is a paragraph.</p></div>

</body>
</html>

Related Tutorials