html - CSS背景层错误
问题描述
我正在尝试在现有的“box-list”div 上实现从 codepen 获取的按钮。
但在我的表单中,按钮获得了父亲的背景,我无法按原样执行我原来的按钮蓝色背景。
在页面底部,您可以看到“box-list”之外的按钮的外观。
<link rel="stylesheet" type="text/css" href="style.css">
<div class="box-list">
<!-- FREE TEXT BOX -->
<div class="box" >
<div class="box__inner">
<h1>Free Text</h1>
Get you free text processed and analyzed, and get opinion summery about.
<button class="analyzeBtn mybtn1" >hover</button>
</div>
</div>
<!-- TWITTER BOX -->
<div class="box" >
<div class="box__inner">
<h1>Twitter Search</h1>
Get Twitter post and comments about any subject you choose and analyze the dat
</div>
</div>
<div class="box" >
<div class="box__inner">
<h1>URL</h1>
Get your URL article analyzed
</div>
</div>
</div>
<button class="analyzeBtn mybtn1" >hover</button>
.box-list {
background: #119bc9;
overflow: hidden;
display: flex;
}
.box {
min-height: 300px;
color: #fff;
transition: all 0.5s;
max-height: 300px;
background-image: url('http://lorempixel.com/400/300/sports');
background-size: cover;
width: 33.33%;
}
.box__inner {
padding: 20px;
min-height: 300px;
background-color: rgba(17, 155, 201, 0.7);
}
.box:hover {
width: 150%!important;
font-size: 18px;
}
.box:nth-child(odd) {
background-image: url('/images/text.jpg');
}
.box:nth-child(odd) .box__inner{
background: rgba(71, 83, 157, 0.8);
}
.analyzeBtn {
border: 1px solid #3498db;
background: none;
padding: 10px 20px;
font-size: 20px;
font-family: "montserrat";
margin: 10px;
transition: 0.8s;
position: relative;
cursor: pointer;
overflow: hidden;
border-radius: 5px;
}
.mybtn1 {
color: #fff;
}
.mybtn1:hover {
color: #3498db;
transform: translateY(-7px);
transition: 0.4s;
}
.analyzeBtn::before {
content: "";
position: absolute;
left: 0;
width: 100%;
height: 0%;
background: #3498db;
z-index: -1;
transition: 0.6s;
}
.mybtn1::before {
top:0;
border-radius: 0 0 50% 50%;
height: 180%;
}
.mybtn1:hover::before {
height: 0%;
}
解决方案
您需要添加z-index: 1;
到按钮,使其显示在背景之上:
.analyzeBtn {
border: 1px solid #3498db;
background: none;
padding: 10px 20px;
font-size: 20px;
font-family: "montserrat";
margin: 10px;
transition: 0.8s;
position: relative;
cursor: pointer;
overflow: hidden;
border-radius: 5px;
z-index: 1;
}
推荐阅读
- r - 避免在R中移动窗口中的循环
- java - 尝试打开 detailactivity 时发生意外崩溃
- c# - 安全地保护和取消保护内存以进行线程处理,只有在所需操作时才不受保护
- flash - Adobe flex - plotseries 的自定义工具提示文本
- php - 无法通过 SendGrid SMTP 服务器向我自己的域发送电子邮件
- python - 中心调整大小的 Qwizard 页面
- ios - react-native-intercom 引发神秘错误 - 架构 x86_64 的未定义符号
- jquery - 无法检查弹出表单中的单选按钮
- angular - 默认选择控制选项上的 ng-valid 类
- python - 为什么 print 语句将输出作为 None 而不是排序列表?