CSS Selector :only-child








The :only-child selector matches the only child element.

Summary

CSS Version
3

CSS Syntax

:only-child {
   style properties 
}

Browser compatibility

:only-child Yes 9.0 Yes Yes Yes




Example

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

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

Click to view the demo