【发布时间】:2018-04-09 12:14:31
【问题描述】:
有人可以向我解释如何在我在图像上创建的蓝色叠加层上方显示我的文本“我想去”和“选择”,这样它们就不会显示为灰色吗? (请看图片)。我知道我可以使用 z-index 和不透明度来实现这一点,但是这些文本元素是我的叠加层的子元素,并且我读到您不能在父元素前面设置子元素。我将如何在我的代码中处理这个问题?
这是我的 html/css:
.panorama {
height:100vh;
min-height:900px;
}
.panorama-overlay {
min-height:900px;
background: rgba(133,216,206,0.57);
opacity: 0.57;
}
.panorama-activity-select-text {
color: #ffffff;
font-family: Futura;
font-size: 38px;
font-weight: 700;
text-transform: uppercase;
text-align:center;
/*line-height: 450px;*/
display:inline;
margin-left:2em;
}
.panorama-activity-select {
color: #ffffff;
font-family: Futura;
font-size: 27px;
font-weight: 700;
text-transform: uppercase;
border: 5px solid #ffffff;
text-align:center;
width: 424px;
height: 57px;
display:inline-block;
vertical-align:middle;
padding-top:0.2em;
margin-left:3em;
cursor:pointer;
}
.select-activity-arrow {
position:absolute;
right:18em;
top:-3.7em;
cursor:pointer;
}
.build-roadtrip-text {
width: 258px;
height: 42px;
color: #ffffff;
font-family: Futura;
font-size: 17px;
font-weight: 700;
text-align:center;
line-height:35px;
margin-top:3em;
border: 2px solid #ffffff;
left:50%;
transform: translateX(-50%);
cursor:pointer;
}
<section class="panorama" style="background: url({{route('cacheImage', ['newDesign', 'panorama.png']) }}) no-repeat; background-size:cover; background-position:center;">
<section class="panorama-overlay">
<div class="vertical-center">
<div class="container">
<div class="row">
<div class="col-md-6">
<p class="panorama-activity-select-text">I WOULD LIKE TO GO</p>
</div>
<div class="col-md-6">
<p class="panorama-activity-select">SELECT</p>
<img src="{{route('cacheImage', ['newDesign', 'select-activity-arrow.png']) }}" class="select-activity-arrow"/>
</div>
</div>
</div>
</div>
<div class="container">
<div class="row">
<div class="col-md-offset-6">
<p class="build-roadtrip-text">BUILD MY ROAD TRIP</p>
</div>
</div>
</div>
</section>
</section><!-- panorama navigation section end -->
【问题讨论】:
-
我看不出问题,但你总是可以使用更高的
z-index -
文本的不透明度没有问题,覆盖是唯一具有编辑不透明度的东西。只需使文本和选择的 z-index 高于叠加层
-
使用多个背景。看我的回答。
-
“我读到你不能在父元素前面设置子元素” 这与 true 完全相反。默认情况下,子级堆叠在父级之上。
标签: html css overlay z-index opacity