gpt4 book ai didi

伪元素后的 CSS(过渡)- 如何过渡悬停时显示的内容

转载 作者:技术小花猫 更新时间:2023-10-29 10:08:34 24 4
gpt4 key购买 nike

<!DOCTYPE html>
<html>
<head>
<style>

div
{
transition:after 3s;
-webkit-transition:after 3s;
}

div:hover:after
{
content:"- positive!";
}
</style>
</head>
<body>

<div>Test</div>

</body>
</html>

我上面有这个示例代码。我正在尝试使用“过渡”,以便文本:“- positive!”需要 3 秒才能滑动/显示。但它不起作用..如何解决?

最佳答案

after 不是 transition 的有效值。

而是将 transition 作为 :after 选择器的属性。

HTML

<div>Test</div>

CSS

div:after {
content:" - positive!";
position: relative;
opacity: 0;
top: -20px;
-webkit-transition: all 3s;
transition: all 3s;
}
div:hover:after {
opacity: 1;
top: 0px;
}

Demo

您还可以对悬停进入和悬停离开状态进行不同的转换。这使我们可以延迟显示伪元素,但不会延迟隐藏它。

CSS

div:after {
content:" - positive!";
position: relative;
opacity: 0;
top: -20px;
-webkit-transition: all 250ms;
transition: all 250ms;
}
div:hover:after {
opacity: 1;
top: 0px;
-webkit-transition: all 3s;
transition: all 3s;
}

Demo

以下是支持伪元素转换的浏览器列表: http://css-tricks.com/transitions-and-animations-on-css-generated-content/

关于伪元素后的 CSS(过渡)- 如何过渡悬停时显示的内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19579340/

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