I have this simple code:
<div class='card'>
<div class='upper-body"> .. </div>
<div class="lower-body"> .. </div>
</div>
I want when you hover over the upper-body, a border to be added on the entire card, but when you hover over the lower-body, nothing to be added. The upper-body is basically the entire card, and the lower-body is the button at the bottom of the Card.
I tried this:
.card {
&:hover:not(.lower-body) {
cursor: pointer;
border-color: #0A8276;
}
}
..but it’s not working. Border is added even when I hover over the lower-body. Why? Why is it not excluded?
3
Answers
There are several errors.
<div class='upper-body">
starts with ‘ and ends with ".card { &:hover:not(.lower-body) {
means that you write it for the .card element and not for its children – you shouldn’t use the & character.Use this code:
For SCSS the code is this:
Or if it’s supposed to be all on hover, then this code:
For SCSS the code is this:
there is no way to style an element based on its children hover state.
you can get your desired look by 2 way:
1.add a class using javascript to card when user hover on upper-body and then set border style based on this class.
2.use upper-body::after this way:
For future reference, this is possible with :has. But this is not widely supported yet.