我只想给我的超大屏幕背景图像不透明度0.5。问题在于我的超大屏幕上的文本的不透明度也为0.5。我怎样才能使背景仅具有不透明度而不是文本?
这是自定义css文件:
.jumbotron{
opacity: 0.5;
background-image: url("../img/colorful_planke.jpg");
background-size: cover;
}
.jumbo_text {
color: white;
}
这是巨型HTML
<div class="jumbotron jumbo_text">
<h1 class="display-4 font-weight-bold text-center">Lorum Ipsom</h1><br>
<p class="lead text-center font-weight-bold">Lorum Ipsom | Lorum Ipsom | Lorum Ipsom | Lorum Ipsom |
Lorum Ipsom</p>
</div>
答案 0 :(得分:4)
在图像上设置纯色渐变(具有不透明度)时,您可以使用linear-gradient
做一些小技巧。
.jumbotron{
opacity: 0.5;
background-image: linear-gradient(rgba(0,0,0,0.5), rgba(0,0,0,0.5)), url("https://www.gettyimages.ca/gi-resources/images/Homepage/Hero/UK/CMS_Creative_164657191_Kingfisher.jpg");
background-size: cover;
}
.jumbo_text {
color: white;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.1/css/bootstrap.min.css" rel="stylesheet"/>
<div class="jumbotron jumbo_text">
<h1 class="display-4 font-weight-bold text-center">Lorum Ipsom</h1><br>
<p class="lead text-center font-weight-bold">Lorum Ipsom | Lorum Ipsom | Lorum Ipsom | Lorum Ipsom |
Lorum Ipsom</p>
</div>