【发布时间】:2021-09-18 03:50:12
【问题描述】:
我试图在按钮悬停时将文本颜色从白色更改为黑色,并且代码中的所有内容都很好,除了文本颜色没有改变。有人知道我该怎么做吗?
.main__btn {
font-size: 1.2rem;
background: rgba(0, 0, 0, 0);
padding: 15px 50px;
border-radius: none;
border-color: #fff;
margin-top: 2rem;
cursor: pointer;
position: relative;
transition: all 0.35s;
outline: none;
}
.main__btn a {
position: relative;
z-index: 2;
color: #fff;
text-decoration: none;
}
.main__btn:after {
position: absolute;
content: '';
top: 0;
left: 0;
width: 0;
height: 100%;
background: #ffffff;
transition: all 0.35s;
border-radius: 4px;
}
.main__btn:hover {
color: #000;
}
.main__btn:hover:after {
width: 100%;
}
<button class="main__btn" id="button1"><a href="#">button1</a></button>
【问题讨论】:
-
这能回答你的问题吗? How can I change a button's color on hover?
-
按钮内的锚点无效。没有理由这样做。