gpt4 book ai didi

css - 添加过渡到伪元素 (SASS)

转载 作者:行者123 更新时间:2023-11-28 03:27:21 24 4
gpt4 key购买 nike

我试图在悬停时逐渐更改 div 的背景,而不是立即更改,但是我无法将过渡应用到我的伪元素。这是我试过的 -

@mixin project-styling($url) {
background: url($url);
background-size: cover;
overflow: hidden;
transition: all 2s;

&:hover:after {
background-color: rgba(0, 0, 0, 0.7);
content: '';
width: 400px;
height: 300px;
}
}

div {
@include project-styling('image.png');
}

最佳答案

过渡也需要在伪元素上。当 div 未悬停时,您也没有包含伪元素。

    @mixin project-styling($url) {
background: url($url);
background-size: cover;
overflow: hidden;
transition: all 2s;

&::after {
background-color: rgba(0, 0, 0, 0.7);
content: '';
width: 400px;
height: 300px;
transition: all 2s;
}

&:hover::after {
background-color: rgba(0, 0, 0, 1);
}
}

div {
@include project-styling('image.png');
}

关于css - 添加过渡到伪元素 (SASS),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44913429/

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