html - 轮廓 1px 纯红色不工作比例悬停
问题描述
我有一个这样的PSD。
我想创建像https://www.khaneyeax.com/en/这样的网站,当我将鼠标放在链接上时,链接上会出现一个圆圈。我使用引导程序 4.5。
CSS
ul.navbar-nav > li > a {
padding: 60px 0 16px;
text-align: center;
position: relative;
min-width: 110px;
}
ul.navbar-nav > li > a > i {
position: absolute;
top: 10px;
padding-top: 10px;
left: 0;
font-size: 25px;
right: 0;
}
ul.navbar-nav > li {
position: relative;
left: 0;
right: 0;
margin: auto;
}
ul.navbar-nav > li:before {
content: '';
position: absolute;
height: 1px;
width: 1px;
border-radius: 50%;
outline: solid 1px red;
transition: all 0.3s linear;
left: 0;
right: 0;
top: 35px;
margin: auto;
display: inline-block;
}
ul.navbar-nav > li:hover:before {
transform: scale(30);
outline-width: 1px;
}
一个简单的 HTML HTML
<li class="nav-item active">
<a class="nav-link" href="#">
<i class="fas fa-th-large fa-2x"></i>
<span>Home</span>
</a>
</li>
我看到了这个演示。
解决方案
您可以在按钮上添加一个悬停伪类,并为悬停上的图标添加一个边框以及border-radius
50% 的边框,这将在图标周围添加圆圈。在我的示例中,我为 ICON 使用 span 标签和图像:ul li a:hover span:first-of-type
--> 当我们将鼠标悬停在 a 标签上时,我们会影响span:first-of-type
我示例中的 ICON。它需要对你的 CSS 进行一些调整,但希望你能看到如何使用 CSS psuedo hover 来完成。
编辑:至于动画,将@keyframes
CSS 中的规则添加到伪元素。在我的示例中,我添加了两个持续时间相同的动画。一个用于a
标签background-color
,另一个用于使用“不透明度”设置color
的伪元素。:after
因为这是假的:after
,所以它允许原始图像图标显示出来,而不受动画中不透明度设置的影响。
* {
padding: 0;
margin: 0;
}
a {
text-decoration: none;
}
ul li a {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
padding: 10px;
width: 100px;
border-radius: 10px 10px 0 0;
}
ul li a:hover {
animation: fadebg 0.8s ease-in-out;
background-color: #800080;
color: #FFF;
}
@keyframes fadebg {
from {
color: #000;
background-color: #FFF;
}
to {
color: #FFF;
background-color: #800080;
}
}
ul li a span:last-of-type {
margin-top: 5px;
}
ul li a:hover span:first-of-type:after {
content: '';
animation: fadein 0.8s ease-in-out;
width: 50px;
height: 50px;
position: absolute;
border: 1.5px solid white;
border-radius: 50%;
align-content: center;
left: 32px;
padding: 2px;
opacity: 1;
}
@keyframes fadein {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
.icon {
width: 50px;
height: 50px;
}
li span {
display: block;
}
li {
list-style-type: none;
}
<ul>
<li class="nav-item active">
<a class="nav-link" href="#">
<span><img class="icon" src="https://cdn2.iconfinder.com/data/icons/minimal-set-two/32/minimal-39-128.png"></span>
<span>Home</span>
</a>
</li>
</ul>
推荐阅读
- powerbi - 切片器仅显示月/年并对其进行过滤
- csv - 如何在朱莉娅的 CSV 文件中保存代码的输出
- bash - Gradle 输出在 VS Code 的 bash 终端中未正确格式化
- winforms - Windows 窗体子菜单自动隐藏延迟 - 如何保持子菜单短暂打开以获得更宽容的鼠标控制
- java - 如何在 Intellij 的类路径上添加一个类?
- azure-devops - 如何在 Azure Devops 中的审阅者选择之前隐藏大型代码块?
- angular - 笑话:无法设置未定义的属性“”(Angular)
- c# - 如何在我的代码中解决此问题。“参数 1:不能将字符串转换为布尔值”
- python - 使用 Pipenv 和 setup.py 将包发布并安装到 Github
- asp.net - 使用 ASP.NET Web Api 和 Angular 10 进行授权