html - CSS边框半径设置为悬停和悬停过渡1s
问题描述
我有一个按钮。在悬停时增加它的宽度并改变边界半径,过渡为 1s。但是在使用初始值(在本例中为 50%)设置的边界半径上立即悬停。我想等待 1 秒,然后在悬停时将边框半径设置为 50%。
.profile-avatar-change {
font-size: 1.8rem;
color: #ffffff;
background: linear-gradient(#fd1999, #a60fe7);
border-radius: 50%;
padding: 5px;
}
.profile-avatar-change:hover {
border-radius: 6px;
}
.profile-avatar-change:hover .hover-text {
opacity: 1;
width: auto;
max-width: 50rem;
}
.profile-avatar-change .hover-text {
position: relative;
white-space: nowrap;
display: inline-block;
visibility: none;
width: auto;
max-width: 0px;
opacity: 0;
text-align: center;
transition: all 1s;
}
<link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" integrity="sha384-wvfXpqpZZVQGK6TAh5PVlGOfQNHSoD2xbE+QkPxCAFlNEevoEH3Sl0sibVcOQVnN" crossorigin="anonymous">
<a src="https://codepen.io/robin3317/pen/zYYwxEB/license">MIT License</a> <br><br>
<a class="profile-avatar-change" href="#">
<i class="fa fa-pencil"></i>
<span class="hover-text">Edit Profile Picture</span>
</a>
这是codepen演示(我使用SCSS作为CSS pre)
解决方案
您可以添加一个延迟为 1 秒的转换,该转换在项目未悬停时运行:
.profile-avatar-change:not(:hover) {
transition: border-radius 1s 1s;
}
演示:
.profile-avatar-change {
font-size: 1.8rem;
color: #ffffff;
background: linear-gradient(#fd1999, #a60fe7);
border-radius: 50%;
padding: 5px;
}
.profile-avatar-change:hover {
border-radius: 6px;
}
.profile-avatar-change:not(:hover) {
transition: border-radius 1s 1s;
}
.profile-avatar-change:hover .hover-text {
opacity: 1;
width: auto;
max-width: 50rem;
}
.profile-avatar-change .hover-text {
position: relative;
white-space: nowrap;
display: inline-block;
visibility: none;
width: auto;
max-width: 0px;
opacity: 0;
text-align: center;
transition: all 1s;
}
<link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" integrity="sha384-wvfXpqpZZVQGK6TAh5PVlGOfQNHSoD2xbE+QkPxCAFlNEevoEH3Sl0sibVcOQVnN" crossorigin="anonymous">
<a src="https://codepen.io/robin3317/pen/zYYwxEB/license">MIT License</a> <br><br>
<a class="profile-avatar-change" href="#">
<i class="fa fa-pencil"></i>
<span class="hover-text">Edit Profile Picture</span>
</a>
推荐阅读
- javascript - 如何从 iframe Google 表格访问单元格数据
- angular - .net 核心和 Angular 7 项目
- aws-appsync - 在 AppSync / Amplify 中过滤非标量类型的解析器
- c# - 如何对 Azure Webjobs V3 进行集成测试?
- mongodb - 如何在 mongodb 中使用 $project 在数组中显示特定字段
- ios - 如何检查功能是否完成?
- python - read_template 的通配符
- java - com.sun.xml.messaging.saaj.SOAPExceptionImpl:无效的内容类型:文本/纯文本。这是错误消息而不是 SOAP 响应吗?
- java - 比较从文本文件中读取的双打
- swift - 如何将角半径添加到 UIStackView 和遮罩子视图