I want to give the background image only in my jumbotron an opacity of 0.5. The problem is that the text in my jumbotron then also has a opacity of 0.5. How can I get the background only to have the opacity and not the text?
Here's the custom css file:
.jumbotron{
opacity: 0.5;
background-image: url("../img/colorful_planke.jpg");
background-size: cover;
}
.jumbo_text {
color: white;
}
Here's the jumbotron 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>
The percentage of opacity is calculated as Opacity% = Opacity * 100 To set the opacity only to the background and not the text inside it. It can be set by using the RGBA color values instead of the opacity property because using the opacity property can make the text inside it fully transparent element.
If you'd like to set the opacity of an element without affecting its child elements, then you need to use the CSS shorthand background property and RGBA color values instead. RGB color codes is one way you can change the text color or background color of a web page in CSS.
You can do a small trick with linear-gradient
when you set a solid color gradient (with opacity) over an image.
.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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With