E:only-child

Matches an E element, that is the only child of its parent. (Source: W3C)

HTML:

  1. <div>
  2. <p>Lorem ipsum dolor sit amet, consectetur</p>
  3. <p>Lorem ipsum dolor sit amet, consectetur</p>
  4. </div>
  5. <div>
  6. <p>Lorem ipsum dolor sit amet, consectetur</p>
  7. </div>

CSS:

  1. p:only-child{font-style:italic}

Output:

Lorem ipsum dolor sit amet, consectetur

Lorem ipsum dolor sit amet, consectetur

Lorem ipsum dolor sit amet, consectetur

In the example, the third line of text should be set in italics as it is the only element in its parent element.