Parent and child elements in CSS
by danielkwood
HTML
<html>
<head>
<title>Parent and child elements</title>
<link rel="stylesheet" href="theme.css" type="text/css"/>
</head>
<body>
<p>This text is not inside a div</p>
<div>
<p>This text is within a div</p>
</div>
<div class="mydiv">
<p>This text is within a div with a class</p>
<p class="mytext">This text has a class and is within a div with a class</p>
</div>
</body>
</html>
CSS
p{
color: blue;
}
div p{
color: red;
}
.mydiv p{
color: purple;
}
.mydiv .mytext{
color: green;
}