[英]CSS: Add background-image to :after pseudoelement with fade effect
#gallery div::after {
content: "";
position: absolute;
top: 0;
}
#gallery div:hover::after {
background-image: url("files/img/plus.jpg") !important;
background-repeat: no-repeat;
height: 83px;
right: 0;
width: 83px;
transition: background 1300ms ease-in 2s;
}
#gallery a:nth-child(1) div {
background-image: url("files/img/bio/1.jpg");
background-size: cover;
height: 240px;
position: relative;
width: 240px;
}
I'm trying to add a fade effect to plus.jpg background-image
, applied on the ::after
pseudoelement on hover
.我正在尝试向 plus.jpg background-image
添加淡入淡出效果,应用于::after
伪元素 on hover
。 As you can see I tried with transition: background 1300ms ease-in 2s
but nothing is happening..正如你所看到的,我尝试过transition: background 1300ms ease-in 2s
但什么也没发生..
Here you can see the code live (is the gallery with 9 images.在这里您可以实时查看代码(是带有 9 张图像的图库。
Try this out. 试试看
#gallery div::after { content: ""; position: absolute; top: 0; height: 83px; right: 0; width: 83px; transition: opacity 1300ms ease-in 2s; background-image: url("files/img/plus.jpg") !important; background-repeat: no-repeat; opacity: 0; } #gallery div:hover::after { opacity: 1; } #gallery a:nth-child(1) div { background-image: url("files/img/bio/1.jpg"); background-size: cover; height: 240px; position: relative; width: 240px; }
background-images can't be transitioned. 背景图片无法转换。 But since it's just a simple plus sign, I suggest the ff: 但是由于这只是一个简单的加号,所以我建议使用ff:
#gallery div::after {
background-color: #ddaa44;
color: white;
content: "+";
display: block;
font: 44px/44px verdana;
opacity: 0;
padding: 26px;
position: absolute;
right: 0;
top: 0;
}
#gallery div:hover::after {
opacity: 1;
transition: all 0.2s ease-in-out 0s;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.