gpt4 book ai didi

css - SVG 背景图像悬停时奇怪的过渡行为

转载 作者:行者123 更新时间:2023-11-28 08:36:19 26 4
gpt4 key购买 nike

我有一个带有 svg 作为背景的按钮。 :hover 选择器工作正常,但是当我给它一个过渡时,按钮首先变小,然后跳回到原来的大小。我该如何阻止这种行为?

这是我的代码:

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>

最佳答案

您可以通过为 pseudo 元素添加 background-image 来使用解决方法

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>

关于css - SVG 背景图像悬停时奇怪的过渡行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29644539/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com