CSS Tutorial

CSS Style

CSS Layout Style

CSS Float Style

CSS Reference

CSS :only-of-type Selector


What is :only-of-type Selector?

CSS :only-of-type selector matches only one child element of its types and whose are child elements of an parent element.

Browser Compatibility

  • Google Chrome 2+
  • Mozilla Firefox 3+
  • Internet Explorer 9+
  • Opera 9.5+
  • Safari 4+

Note: Here details of browser compatibility with version number may be this is bug and not supported. But recommended to always use latest Web browser.

Syntax

General syntax of :only-of-type selector,

element:only-of-type {
	property: value;
	property: value;
	...
}

/* match all sibling of its type child element */
element *:only-of-type {
	property: value;
	property: value;
	...
}

Example:

CSS :only-of-type selector matches only one element of its types and whose are child elements of an parent element.

<style type="text/css">
li:only-of-type {
	background:#ff0000;
}
</style>
</head>
<body>
    <ul>
        <li>This is first line</li>
    </ul>
    <ul>
        <li>This is first line</li>
        <li>This is second line</li>
        <li>This is third line</li>
    </ul>
    <p>
        <span>This is first paragraph</span>
    </p> 
</body>

Run it...   »

Example Result: