Adjusting the transparency of my banner background image using Bootstrap 4

How can I make the background image transparent without affecting other elements like the navigation menu and main text?

After researching online, I discovered that overlaying with a white image of the same size could be the solution.

However, when attempting to implement this method, all elements on the page seem to become transparent. Any idea why this is happening?

HTML:

<html>

  <div class="container-fluid">

<div class="banner-img">
    <ul class="nav nav-pills">
  <li class="nav-item">
    <a class="nav-link active" href="#">Kintesh</a>
  </li>
  <li class="nav-item">
    <a class="nav-link" href="#">CV</a>
  </li>
  <li class="nav-item">
    <a class="nav-link" href="#">Portfolio</a>
  </li>
  <li class="nav-item">
    <a class="nav-link disabled" href="#">Contact</a>
  </li>
</ul>


        <div class="col-xs-2 logo text-center"><span class="welcome-text-bold">K</span>intesh <span class="welcome-text-bold">P</span>atel</div>
    </div>

      <div class="blurb">
    Some interesting stuff goes here, I guess?
  </div>

  </div> <!-- End of container-fluid -->
</html>

CSS:

/* 
Dark Grey: #A9A9A9;
Light white: #8C8D8D;
Watermelon for vibrancy: #FC0B56;
Light grey for reasons: #8C8D8D;
Orange: #e37222;
Blue: #CAEBF2;

Canary wharf img url: https://image.ibb.co/kZ0n0Q/boris_stefanik_119208.jpg
*/

/* 
font-family: 'Ubuntu', sans-serif;
font-family: 'Lobster', cursive;
font-family: 'Pacifico', cursive;
font-family: 'Asap', sans-serif; 
*/

@import url('https://fonts.googleapis.com/css?family=Asap|Lobster|Pacifico|Ubuntu');


body, html {
  background-color: #fff;
  height: 100%;
}

body {
  padding-top: 0px;
}

.banner-img {
    position: relative;
    background: #fff;
    overflow: hidden;
}

.banner-img:before {
    content: ' ';
    display: block;
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
    opacity: 0.5;
    background-repeat: no-repeat;
    background-position: 0% 50%;
    -ms-background-size: cover;
    -o-background-size: cover;
    -moz-background-size: cover;
    -webkit-background-size: cover;
    background-size: cover;
    background-image:url('https://image.ibb.co/kZ0n0Q/boris_stefanik_119208.jpg');
}



.content {
    position:absolute; 
    width:100%; 
    top:100%; 
    height: 100px;
}

.container-fluid {
  padding: 0px;
  background-color: #fff;
}


.welcome-text-bold {
  color: #FC0B56;
}

.logo {
  color: #efefef;
  font-weight: 800;
  font-size: 5em;
  padding: 5%;
  text-align: center;
/*   font-family: 'Pacifico', cursive; */
  font-family: 'Asap', sans-serif;
  text-align: center;
}

Answer №1

To ensure elements are positioned on top of the transparent image, add position: relative; z-index: 1; to them.

Here is the CSS code:

@import url('https://fonts.googleapis.com/css?family=Asap|Lobster|Pacifico|Ubuntu');

body, html {
  background-color: #fff;
  height: 100%;
}

body {
  padding-top: 0px;
}

.banner-img {
    position: relative;
    background: #fff;
    overflow: hidden;
}

.banner-img:before {
    content: ' ';
    display: block;
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
    opacity: 0.5;
    background-repeat: no-repeat;
    background-position: 0% 50%;
    -ms-background-size: cover;
    -o-background-size: cover;
    -moz-background-size: cover;
    -webkit-background-size: cover;
    background-size: cover;
    background-image:url('https://image.ibb.co/kZ0n0Q/boris_stefanik_119208.jpg');
}



.content {
    position:absolute; 
    width:100%; 
    top:100%; 
    height: 100px;
}

.container-fluid {
  padding: 0px;
  background-color: #fff;
}


.welcome-text-bold {
  color: #FC0B56;
}

/* Updated CSS for nav ul */
ul {
  position: relative;
  z-index: 1;
}

/* Additional styling for logo */
.logo {
  position: relative;
  z-index: 1;
  color: #efefef;
  font-weight: 800;
  font-size: 5em;
  padding: 5%;
  text-align: center;
  font-family: 'Asap', sans-serif;
}

If you encounter any issues, feel free to reach out.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

How to Align Item at Center in Bootstrap 5 Jumbotron

My jumbotron contains the bx-message-error icon that I want to center both horizontally and vertically in a row. Despite searching online and going through the documentation, I haven't been able to align it. I'm sure it's a simple fix, so an ...

Centering text in a pseudo element vertically

I’ve been trying to find a way to centrally position vertically an ::after pseudo-element that includes text (a content attribute). Previous inquiries: I reviewed some previous inquiries on this topic, however, none of the solutions seem to apply to thi ...

Create a grid layout of Bootstrap Cards using ReactJS

Looking to dynamically render Bootstrap cards based on the number of players. When there are 4 players, they should be displayed in a single column. However, when there are 5 or more players, I want the cards to spread out into two columns. What would be ...

CSS hover effect: altering background colors of both parent and child elements simultaneously

HTML: <div class="container"> <div class="parent">one <div class="child">two</div> </div> </div> CSS: .parent { background: red; height: 200px; width: 200px; } .child { back ...

"Accessing and updating the current navigation state using jQuery/ajax when clicked

Currently, I'm working on a website project where I am using a jquery/ajax script to dynamically pull in content from another page with a fade effect when clicking on a tab in the navigation menu. You can check out the effect on the page here. Only th ...

Preventing the elements within a div section from shifting position

I am facing an issue with a div section that contains multiple <a href=""> tags. When I shrink the div section on the page, the contents move when a user tabs into it. Is there a way to lock the div section so that its contents do not move? For exam ...

Transforming card dimensions with Bootstrap

I am currently working on my web portfolio and I am looking to create a card format that includes an image thumbnail with text below it. However, I am facing an issue where I cannot control the size of the initial image, resulting in misaligned cards. htt ...

Difficulty understanding JavaScript sum calculations

I am currently working on a website project. Seeking assistance to enable an increment of one when clicked. Also need guidance on calculating the total price of items collected in a designated section under "number of items selected". Goal is to display ...

Utilizing background images in CSS to enhance bootstrap icons

Here is the HTML code snippet I'm working with: <a class="iconContainer" href="#"> <span class="containerIcon chevron-right"/> Test </a> And this is the corresponding CSS code: .chevron-right::befor ...

Why is my CSS media query failing to increase font size?

I can't seem to get the "media query" function to work properly. I've tried multiple times and searched for a solution without any luck. Below is the code snippet where I'm attempting to increase the font size from 44px to 70px on small devi ...

Changing the size of an iframe and closing it by pressing the ESC

I am developing an application that requires the ability to resize an iframe. When the user clicks the "Full Screen" button, the iframe should expand to occupy the entire screen. The iframe should return to its original size when the user presses the "Es ...

Controlling the Flow of Events in JavaScript Documents

Explore the integration of two interconnected Javascript files and delve into managing event propagation between them effectively. 1st js file var red = [0, 100, 63]; var orange = [40, 100, 60]; var green = [75, 100, 40]; var blue = [196, 77, 55]; var ...

Should I implement jquery within angular 2, or opt for the current css/js frameworks available?

Embarking on the development of a website with Angular 2, my deadline is set within a month. I need to select a CSS/JS framework that seamlessly integrates with Angular 2. While using jQuery within Angular 2 is discouraged, I am curious if there are altern ...

In JavaScript, I'm facing an issue where I can't seem to use ' ' for line breaks for some reason. It's not functioning as expected, and I'm

It seems that I have been struggling with writing a new line in my code using "\n". Despite multiple attempts, the desired outcome has not been achieved. Below is my source code along with a screenshot of the result: var ary3 = new Array('seve ...

Tips for aligning the Bootstrap inline form in the center of the webpage

Is there a way to center align my form in such a way that the input box and button appear in the same row? I've tried the code below, but for some reason they don't display inline. Can anyone provide a code sample to help me achieve this? Your as ...

Adding new data to a Chart.js line graph in vue on form submission - A step-by-step guide

I'm struggling with dynamically updating my line chart with new data. I want the chart to refresh every time a user submits a form with new data. Currently, I can add new data to the datasets array in the data function of App.vue, but the chart doesn& ...

The CSS selector for attribute ending with a specific value is not functioning as anticipated

I am facing an issue with selecting elements based on classes ending with either x-control-ui or y-control-ui: <div class="x-control-ui">x-control: <output id="x-control-output"></output></div> <input type=&q ...

Achieving nested classes in CSS: a comprehensive guide

I am encountering an issue with my CSS while trying to create a dropdown on hover. The problem seems to be related to nested classes inside a div structure. It appears that the dropdown list is not displaying properly, leading me to believe there might be ...

The functionality of the disabled button is malfunctioning in the Angular 6 framework

Just starting out with angular 6 and I'm using formControl instead of FormGroup for business reasons. app.component.html <button class="col-sm-12" [disabled]="comittee_Member_Name.invalid && comittee_Member_Number.invalid && c ...

How can I make the navbar in Angular stay fixed in place?

After using the ng generate @angular/material:material-nav --name=home command to create a navbar, I am trying to make it fixed at the top while scrolling. I attempted using position: fixed; on my mat-sidenav-content but it didn't work. Does anyone ha ...