Answer the question
In order to leave comments, you need to log in
How to make inheritance only for child element, excluding grandchildren and great-grandchildren?
Hello!
As you can see in the code below, the container div is the parent of Test1. Test1 nests Test2, and Test2 nests Test 3. Test 1 is the child of the div, Test 2 is the "grandchild" and Test 3 is the "great-grandchild". I want the red color to inherit only the child paragraph Test, excluding "grandchild" and "great-grandchild", so I wrote: div > p{,
but it didn't work, what's my mistake?
<!DOCTYPE html>
<html>
<head>
<title>TEST</title>
<style>
div > p{
color:red;
}
</style>
</head>
<body>
<div id="z">
<p>TEST1
<p>TEST2
<p>TEST3</p>
</p>
</p>
</div>
</body>
</html>
Answer the question
In order to leave comments, you need to log in
From the standard :
So from the browser's point of view, your html code looks like:
<body>
<div id="z">
<p>TEST1 </p>
<p>TEST2 </p>
<p>TEST3 </p>
</p>
</p>
</div>
</body>
div > p {
color: red;
}
div > p > * {
color: black;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question