Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add animation to a bootstrap 4 card on hover?

Tags:

html

css

I have a card to which I would like to apply some basic animation like - zoom in effect and border color change on hover. I have tried several methods but nothing is working for me. Many similar questions have been asked before, and I tried a few but not getting satisfactory result.

Below is my code -

HTML

<div class="container">
<a class=" text-decoration-none " href="">
<div class="card">
<img class="icon" src=""/>
<div class="card-text">
AlphaBetaGamma
</div>
<div class="d-flex align-items-center justify-content-end">
<span class="read-more">READ MORE</span>
<i class="fas fa-arrow-circle-right"></i>
</div>
</div>
</a>
</div>

CSS-

.card .read-more:hover{
    font-size: 14px;
}

.card :hover{
    box-shadow: 8px 8px 8px blue;
}

The box shadow part is not working for some reason. I would also like the text on the card to grow a little when the card zooms and a blue shadow should add.

How can I achieve this ?

like image 433
Ityka Bandta Avatar asked Dec 03 '22 17:12

Ityka Bandta


1 Answers

For smooth transitional effects, add 'transition' to the element you'd like to target. Then in the hover selector, change the dimensions and it should happen with a smoother transition.

Same with color changes etc.. This is just one of the ways.

.card .read-more:hover{
    font-size: 14px;
}

.card:hover{
    box-shadow: 8px 8px 8px blue;
    transform:scale(1.2);
}

.card{
  height:200px;
  width:200px;
  border:1px solid black;
  transition:.3s;
  margin: 3rem;
}
    <div class="container">
      <a class=" text-decoration-none " href="">
        <div class="card m-5">
          <img class="icon" src=""/>
          <div class="card-text">
          AlphaBetaGamma
          </div>
          <div class="d-flex align-items-center justify-content-end">
            <span class="read-more">READ MORE</span>
            <i class="fas fa-arrow-circle-right"></i>
          </div>
        </div>
      </a>
   </div>
like image 96
Tyler Watts Avatar answered Dec 11 '22 17:12

Tyler Watts