html - 按钮中的文本进入:状态之前
问题描述
我正在使用此codepen中的第三个按钮。
.btn {
line-height: 50px;
height: 50px;
text-align: center;
width: 250px;
cursor: pointer;
}
.btn-three {
color: #FFF;
transition: all 0.5s;
position: relative;
}
.btn-three::before {
content: '';
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: 1;
background-color: rgba(0,0,0,1);
transition: all 0.3s;
}
.btn-three:hover::before {
opacity: 0 ;
transform: scale(0.5,0.5);
}
.btn-three::after {
content: '';
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: 1;
opacity: 0;
transition: all 0.3s;
border: 1px solid rgba(255,255,255,0.5);
transform: scale(1.2,1.2);
}
.btn-three:hover::after {
opacity: 1;
transform: scale(1,1);
}
每当我将按钮背景的不透明度更改为完全黑色时,文本在 :before 状态下完全消失。
这有什么原因吗?似乎文本与按钮位于同一“层”中,而不是在其顶部
解决方案
我建议将锚链接移到按钮标签之外,并使用 z-index 将文本强制放在前面。
CSS:
.btn-three {
transition: all 0.5s;
position: relative;
line-height: 25px;
height: 50px;
align-items: center;
text-align: center;
width: 250px;
cursor: pointer;
}
.btn-three::before {
content: '';
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: 1;
background-color: rgba(16, 84, 35, 1);
transition: all 0.3s;
}
.btn-three:hover::before {
opacity: 0 ;
transform: scale(0.5,0.5);
}
.btn-three::after {
content: '';
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
opacity: 0;
transition: all 0.3s;
border: 1px solid rgba(0, 0, 0, 0.5);
transform: scale(1.2,1.2);
z-index: 2;
}
.three-text {
position: relative;
margin-top: -10px;
z-index: 1;
display: block;
}
.btn-three:hover::after {
opacity: 1;
transform: scale(1,1);
}
.button-wrapper {
padding-top: 3%;
text-align: center;
padding-bottom: 3%;
}
HTML:
<div class="button-wrapper">
<button class="btn btn-three" />
<a class="three-text">HERE YOUR TEXT</a>
</div>
推荐阅读
- c# - 在表格渲染之前将行标记为选中
- javascript - 使用 js 对 API 调用响应进行排序
- r - 删除满足条件的 2 个连续行
- php - Sum parts of an array in php
- javascript - 无法在 react-native 上下文 api 中读取未定义的属性“状态”?
- ios - iOS 自定义视图,更改 UILabel textColor/isHidden 不起作用
- java - 在java中从mongo中提取ObjectId
- json - 具有所有数字名称的 Swift JSON 变量。有什么工作?
- azure - 查询 CosmosDb 非结构化 JSON
- python - 不明白python中的内部函数