CSS Selector :only-of-type








The :only-of-type selector matches elements that are the only child of their type.

Summary

CSS Version
3

CSS Syntax

:only-of-type {
   style properties 
}

Browser compatibility

:only-of-type Yes 9.0 Yes Yes Yes




Example

An example showing how to use :only-of-type CSS selector.

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

Click to view the demo