Reputation: 11338
How to define a CSS selector that targets only the highest level element of itself, but not those elements that are nested within the same selector itself?
For example the style rules gets applied to .card
element, but not .card .card
or .card .card .card
elements... ?
Upvotes: 0
Views: 83
Reputation: 14191
You can negate the styling of the children with the Descendant combinator
.card {
border: 1px solid black; /* orig style */
height: 200px;
width: 50%;
}
.card {
border: 5px solid red; /* "highest level element of itself" */
}
.card .card {
border: 1px solid black; /* children of the "highest level element" */
}
<body>
<div class="card">
<div class="card">
<div class="card"></div>
</div>
</div>
</body>
Upvotes: 1