gpt4 book ai didi

html - 如何在将指针移开时使用 CSS 使文本单独消失

转载 作者:行者123 更新时间:2023-11-28 14:44:58 25 4
gpt4 key购买 nike

Problamatic Animation

我试图在悬停时显示文本“Follow me”。文本显示正常,但将鼠标指针移开后,文本会折叠并消失。

有没有办法在将指针移开时立即隐藏文本?

这是我的 HTML 和 CSS,展示了我是如何实现当前效果的:

.fa {
padding: 20px 20px;
font-size: 1.4rem;
width: 25px;
text-align: center;
text-decoration: none;
transition: all ease 0.4s;
font-family: 'Roboto', sans-serif;
border-radius: 5px;
box-shadow: 0 5px 5px rgba(0, 0, 0, 0.3);
}

.fa:hover {
opacity: 0.9;
}

.fa-google {
background: #DD4B39;
color: white;
position: relative;
font-size: 0pt;
}

.fa-google::after {
position: absolute;
top: 35%;
right: 0.6rem;
content: "Follow Me";
transition: all ease 0.4s;
opacity: 0;
text-transform: uppercase;
font-family: 'Roboto', sans-serif;
}

.fa-google:hover {
padding: 20px 130px 20px 20px;
}

.fa-google:hover::after {
right: 1.2rem;
opacity: 1;
}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">

<div id="page" class="container">
<div class="socialMedia">
<a href="#" class="fa fa-google"></a>
<a href="#" class="fa fa-twitter"></a>
<a href="#" class="fa fa-linkedin"></a>
<a href="#" class="fa fa-github"></a>
</div>
</div>

最佳答案

将过渡移动到 ::after 元素的悬停定义。过渡将仅在悬停时应用,当您移动光标时,::after 将立即消失。

.fa-google:hover::after {
right: 1.2rem;
opacity: 1;
transition: all ease 0.4s;
}

示例:

.fa {
padding: 20px 20px;
font-size: 1.4rem;
width: 25px;
text-align: center;
text-decoration: none;
transition: all ease 0.4s;
font-family: 'Roboto', sans-serif;
border-radius: 5px;
box-shadow: 0 5px 5px rgba(0, 0, 0, 0.3);
}

.fa:hover {
opacity: 0.9;
}

.fa-google {
background: #DD4B39;
color: white;
position: relative;
font-size: 0pt;
}

.fa-google::after {
position: absolute;
top: 35%;
right: 0.6rem;
content: "Follow Me";
opacity: 0;
text-transform: uppercase;
font-family: 'Roboto', sans-serif;
}

.fa-google:hover {
padding: 20px 130px 20px 20px;
}

.fa-google:hover::after {
right: 1.2rem;
opacity: 1;
transition: all ease 0.4s;
}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<div id="page" class="container">
<div class="socialMedia">
<a href="https://plus.google.com/u/0/+DivakarRajesh" class="fa fa-google"></a>
<a href="https://mobile.twitter.com/DivakarRajeshS" class="fa fa-twitter"></a>
<a href="https://www.linkedin.com/in/sdivakarrajesh/" class="fa fa-linkedin"></a>
<a href="https://github.com/sdivakarrajesh" class="fa fa-github"></a>
</div>
</div>

关于html - 如何在将指针移开时使用 CSS 使文本单独消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52430055/

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