I have a .card which shows an arrow by default. When a user hovers over this .card, I want the "learn more" text to slide in from the right and move the arrow with it.
I have tried to put .card__footer to width: 0; then try give it width on hover, but, because the text is transitioning in, sometimes it appears on two lines, then once transition is over, becomes one line.
How can I get this effect to work on hover besides using width? Or what is the correct way to implement it? My current approach:
.cards {
background: lightblue;
padding: 60px 0;
}
.container {
max-width: 720px;
display: flex;
justify-content: space-between;
align-items: center;
margin: 0 auto;
}
.card {
background-color: white;
padding: 30px;
cursor: pointer;
transition: all 0.5s ease;
width: 250px;
}
.card:hover {
box-shadow: 0px 20px 25px 0px rgba(0, 0, 0, 0.1);
}
.card:hover .card__arrow {
transform: translateX(5px);
}
.card:hover .card__label {
display: inline-block;
visibility: visible;
margin-right: 6px;
opacity: 1;
}
.card__header {
margin-bottom: 30px;
}
.card__footer {
display: flex;
justify-content: flex-start;
align-items: center;
}
.card__label {
margin-right: 10px;
}
@media (hover: hover) {
.card__label {
margin: 0;
transition: opacity 0.5s;
visibility: hidden;
opacity: 0;
display: none;
}
}
<div class="cards">
<div class="container">
<div class="card">
<div class="card__header">
header
</div>
<div class="card__footer">
<span class="card__label">Learn more</span>
<img class="card__arrow" src="https://i.imgur.com/onjXVGW.png" alt="arrow" />
</div>
</div>
<div class="card">
<div class="card__header">
header 2
</div>
<div class="card__footer">
<span class="card__label">Learn more</span>
<img class="card__arrow" src="https://i.imgur.com/onjXVGW.png" alt="arrow" />
</div>
</div>
</div>
</div>
What I'm after:
.footer__arrowshows by default left side (as it does in the demo).footer__labelis hidden by default- On
.cardhover, I want the.footer__labelto slide in, pushing thearrowimage with it (so that it shows "learn more" and then the arrow on hover. - Currently my
.footer__labeljust appears, whereas I want the label to slide in slowly and give it the effect that my arrow is being pushed alongside it.