Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jumbotron Bootstrap 4 Image Opacity but Not Text

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>
like image 732
jproux Avatar asked Jun 23 '18 14:06

jproux


People also ask

How do I change the opacity of the background image but not the text?

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.

How do I change the opacity of text without affecting CSS?

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.


1 Answers

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>
like image 182
Eliya Cohen Avatar answered Nov 12 '22 09:11

Eliya Cohen