element>element, parent child - HTML CSS CSS Selector

HTML CSS examples for CSS Selector:element parent child

Description

The element>element selector selects elements with parent child relation.

The element>element selector selects direct child of the specified parent.

Example

Select every <p> element where the parent is a <div> element:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<head>
<style>
div > p {
    background-color: yellow;
}
</style><!--  www .j  a va  2s .c o m-->
</head>
<body>

<h1>Welcome to My Homepage</h1>

<div>
  <h2>this is a test</h2>
  <p>this is a paragraph.</p>
</div>

<div>
  <span><p>I will not be styled.</p></span>
</div>

<p>I <b>like</b> css.</p>

</body>
</html>

Related Tutorials