I’m trying to build this website using only html/css and Bootstrap, and in this instance I want to get that hover effect when I hover over some cards (Cards are from Bootstrap 5), but when I add that :hover in css and hover over a card, it adds border on every subelement of that card, instead of only the outer frame. For example: This is what I want to happen:
but instead I get this:
This is the code I tried:
<div class="row block">
<div class="col-4 card-hover"> <-- This "card-hover" is responsible for hovering
<div class="card-sizedown">
<div class="card gap-3">
<img src="images/croatia luxury booking, villa tinka sumartin.jpg" class="card-img-top" alt="...">
<div class="card-body">
<h4 class="card-title text-family" style="font-weight:600">Villa Tinka - Sumartin <i class="fa fa-star ms-auto" aria-hidden="true" style="font-size: small; color:rgb(197, 136, 43)"></i><i class="fa fa-star ms-auto" aria-hidden="true" style="font-size: small; color:rgb(197, 136, 43)"></i><i class="fa fa-star ms-auto" aria-hidden="true" style="font-size: small; color:rgb(197, 136, 43)"></i><i class="fa fa-star ms-auto" aria-hidden="true" style="font-size: small; color:rgb(197, 136, 43)"></i><i class="fa fa-star ms-auto" aria-hidden="true" style="font-size: small; color:rgb(197, 136, 43)"></i></h4>
<p class="card-text"></p>
<p class="card-text" style="font-weight: 300">Swimming pool - Gym - Sauna - Free Parking -
Free Wi-Fi - EV Charger - Concierge Service
</p>
</div>
</div>
</div>
</div>
</div>
and this is the corresponding css:
.card-hover :hover{
border: 2px solid rgb(197, 136, 43);
}
3
Answers
Looks like you need to use a different CSS selector…
https://codeply.com/p/pDDWOa8xii
Try this following example using Bootstrap 5.
The problem is that you apply styling to any element that is being hovered inside an element with the class
card-hover
. Just remove the space between.card-hover
and:hover
.Update: looks like hover effect should be applied to
.card
, not to.card-hover
, because.card-hover
is added to.col-4
which includes paddings.