CSS Selector :only-child

Description

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

Example


<!DOCTYPE HTML> 
<html> 
    <head> 
        <style type="text/css"> 
        :only-child { <!--from   w  ww.j  a v a  2 s.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

The code above generates the following result.

:only-child




















Home »
  HTML CSS »
    HTML CSS Reference »




HTML Tag Reference
CSS Reference
CSS Selector Reference
Encoding Reference