html - 使用 z-index 但文本仍然没有出现在前面
问题描述
我正在使用 z-index,但我的文字仍然没有超出我在 bg 中的色调。我是编码新手,所以如果我做错了什么,我很抱歉。任何帮助,将不胜感激。
.parallax {
/* The image used */
background-image: url("https://www.lincoln.ac.uk/home/media/responsive2017/studywithus/internationalstudents/gatewayToEurope_1500x996px-min.jpg");
/* Set a specific height */
height: 100%;
/* Create the parallax scrolling effect */
background-attachment: fixed;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
}
.bg-tint {
position: relative;
}
.bg-tint:before {
content: "";
display: block;
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
background: rgba(56,56,56, 0.9);
transition: all .3s linear;
z-index: 2;
}
.bg-tint .content h3 {
z-index: 6;
}
<div class="parallax bg-tint">
<div class="content">
<h3 style="padding-top:200px; padding-bottom: 200px;font-weight: 400; font-size: 64px; color:white;">Covering your location!</h3>
<p>We cover most English speaking countries, including yours!</p>
</div>
</div>
解决方案
添加z-index:3
和position:relative
到.content
。
.parallax {
background: url("https://www.lincoln.ac.uk/home/media/responsive2017/studywithus/internationalstudents/gatewayToEurope_1500x996px-min.jpg") center center no-repeat;
background-attachment: fixed;
background-size: cover;
height: 100%;
}
.bg-tint {
position: relative;
}
.bg-tint:before {
content: "";
display: block;
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
background: rgba(56,56,56, 0.9);
transition: all .3s linear;
z-index: 2;
}
.bg-tint .content {
position:relative;
z-index: 3;
}
.bg-tint .content h2 {
}
<div class="parallax bg-tint">
<div class="content">
<h3 style="padding-top:200px; padding-bottom: 200px;font-weight: 400; font-size: 64px; color:white;">Covering your location!</h3>
<p>We cover most English speaking countries, including yours!</p>
</div>
</div>
推荐阅读
- launch4j - Java 11 在 Windows 7 32 位
- ruby-on-rails - RSpec不输出传递给“它”的语句
- batch-file - 批量2点之间的线
- java - CloudFormation:什么是正则表达式来匹配没有句点(点)的 S3 存储桶名称
- html - 屏幕阅读器和 HTML5 验证
- python - 熊猫 read_sql_table 永远不会解决
- php - 为什么 Internet Explorer 将 filedownload.php/path= 添加到文件的任何链接
- python - 从包导入 * as _
- javascript - 与 Material-UI 反应找不到模块
- android - 我有一个使用 XML 制作的自定义编辑文本,只有在 KITKAT 版本中它具有黑色背景