I have a button with an svg as a background. The :hover
selector works fine but when I give it a transition, the button first gets smaller and then jumps back to the original size. How do I stop this behavior?
here's my code:
a {
width: 250px;
display: block;
color: rgba(0, 0, 0, .9);
text-decoration: none
}
.prod-ueber .cta-wrapper {
position: absolute;
left: 310px;
width: 100px;
top: 45px;
z-index: 5
}
.info-btn,
.korb-btn {
width: 50px;
height: 50px;
background-repeat: no-repeat;
background-size: 100%;
float: left;
transition: background .4s ease;
}
.info-btn {
background-image: url(http://imgh.us/info-btn.svg);
}
.korb-btn {
background-image: url(http://imgh.us/korb-btn.svg);
margin-left: 12px;
}
.info-btn:hover,
.info-btn:active,
.info-btn:focus {
background-image: url(http://imgh.us/info-btn_h.svg);
}
.korb-btn:hover,
.korb-btn:active,
.korb-btn:focus {
background-image: url(http://imgh.us/korb-btn_h.svg);
}
<a href="#">
<div class="prod-ueber">
<img src="http://dummyimage.com/" height="290" width="426" alt="Minze" class="img-responsive">
<h3 class="Artikelname">Malve</h3>
<small>Description</small>
<hr>
<h5 class="preis">€ 1,79</h5>
<div class="cta-wrapper">
<a href="#" class="info-btn"></a>
<a href="#" class="korb-btn"></a>
</div>
</div>
<!-- produkt -->
</a>
You can use a workaround by adding background-image
for the pseudo
element
a {
width: 250px;
display: block;
color: rgba(0, 0, 0, .9);
text-decoration: none
}
.prod-ueber .cta-wrapper {
position: absolute;
left: 310px;
width: 100px;
top: 45px;
z-index: 5
}
.info-btn,
.korb-btn {
width: 50px;
height: 50px;
background-repeat: no-repeat;
background-size: 100%;
float: left;
position: relative;
overflow:hidden;
}
.info-btn {
background-image: url(http://imgh.us/info-btn.svg);
}
.korb-btn {
background-image: url(http://imgh.us/korb-btn.svg);
margin-left: 12px;
}
.info-btn:before,
.korb-btn:before {
content: '';
width: 100%;
height: 100%;
position: absolute;
background-size: 100% auto;
opacity: 0;
transition: .4s ease;
}
.info-btn:before {
background-image: url(http://imgh.us/info-btn_h.svg);
}
.korb-btn:before {
background-image: url(http://imgh.us/korb-btn_h.svg);
}
.info-btn:hover:before,
.info-btn:active:before,
.info-btn:focus:before {
opacity: 1;
}
.korb-btn:hover:before,
.korb-btn:active:before,
.korb-btn:focus:before {
opacity: 1;
}
<a href="#">
<div class="prod-ueber">
<img src="http://dummyimage.com/" height="290" width="426" alt="Minze" class="img-responsive">
<h3 class="Artikelname">Malve</h3>
<small>Description</small>
<hr>
<h5 class="preis">€ 1,79</h5>
<div class="cta-wrapper">
<a href="#" class="info-btn"></a>
<a href="#" class="korb-btn"></a>
</div>
</div>
</a>
Instead of setting the background of the image you can just set in the svg element itself. It might make you html a bit bigger but you can set the <svg> in a template.
First lets just use a svg instead of background. (svg is xhtml so you can just paste it in html)
#Ebene_1 circle {
transition: fill .4s, stroke .4s;
}
#Ebene_1:hover circle {
fill: #ffe;
}
#Ebene_1:hover path {
fill: #b61910;
}
<p>We can use the svg inside our html :D</p>
<svg version="1.1" id="Ebene_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="60.1px" height="60.1px" viewBox="0 0 60.1 60.1">
<circle fill="#B61910" stroke="#B61910" stroke-width="1.5" stroke-miterlimit="10" cx="30.1" cy="30.1" r="29.3" />
<path fill="#FFFFFF" d="M32.3,14c1.6,0,3.2,1.6,3.2,3.2S33.9,22,30.7,22c-1.6,0-3.2-1.6-3.2-3.2C29.2,15.6,30.7,14,32.3,14z
M26,45.8c-1.6,0-3.2-1.6-1.6-6.4l1.6-7.9c0-1.6,0-1.6,0-1.6s-3.2,1.6-4.8,1.6v-1.6c4.8-3.2,9.5-4.8,11.1-4.8
c1.6,0,1.6,1.6,1.6,4.8l-1.6,7.9c0,1.6,0,1.6,0,1.6s1.6,0,3.2-1.6l1.6,1.6C32.3,44.2,27.6,45.8,26,45.8z" />
<rect x="8.2" y="14.2" fill="none" width="36.5" height="31.8" />
</svg>
<p>and it wil :hover. <br> Added some transitions to.</p>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With