【发布时间】:2022-01-25 06:24:00
【问题描述】:
我正在尝试制作一个简单的导航菜单,其中包含带有动画下划线的按钮。我正在使用 reactjs 库
如果按钮元素处于活动状态,我不知道如何让下划线立即可见。
.btn {
position: relative;
text-transform: uppercase;
color: whitesmoke;
font-size: 1.4rem;
cursor: pointer;
}
.btn:hover {
color: whitesmoke;
text-decoration: none;
}
.btn:before {
content: "";
position: absolute;
width: 100%;
height: 0.105rem;
left: 0;
bottom: 0;
visibility: hidden;
background-color: whitesmoke;
transform: scaleX(0);
transition: all 0.3s ease-in-out 0s;
}
.btn:hover:before {
transform: scaleX(1);
visibility: visible;
}
button.active .btn:before {
visibility: visible;
transform: scaleX(1);
}
<a href="/">
<button id="home" className="btn active">
Home
</button>
</a>
</div>
<div className="col-4 col-sm-2">
<a href="/blog">
<button id="blog" className="btn">
Blog
</button>
</a>
【问题讨论】:
-
您的 HTML 无效。此外,
className应该是class,除非您使用的是 react 之类的库 -
button:active,而不是button.active,在这种情况下,button .btn应该是button.btn- 但我会完全删除btn类,它是多余的。 -
@Dai 仍然无法正常工作。