Step by step guide on incorporating two background images in a single header

I'm looking to create a header with a background image that appears twice, like this:

To achieve the effect, I added opacity of 0.5 to one of the images, but it is affecting everything in my header including text and logo. Is there a way to prevent the text and logo from being affected by the opacity applied to the header banner?

/* Styling for marketing business main header */
.marketing-navbar_items {
    font-family: Helvetica Neue;
    font-size: 30px;
    font-weight: normal;
    color: #FFFFFF;
}

.marketing-main-header_banner {
    background-image: url("https://svgshare.com/i/8KR.svg");
    background-size: auto 1199px;
    background-repeat: no-repeat;
    background-position: center -250px;
    position: relative;
    height: 949px;
}

.sample {
    background-image: url("https://svgshare.com/i/8KR.svg");
    background-size: auto 1199px;
    background-repeat: no-repeat;
    background-position: center -250px;
    position: absolute;
    height: 949px;
    opacity: 0.5;
}

.marketing-main-header_details {
    display: flex;
    justify-content: center;
    flex-direction: column;
    align-items: center;
    margin-top: 30px;
}

.marketing-main-header_description p {
    font-size: 30px;
    font-family: HeaderFont;
    color: white;
    /* width: 55%; */
    text-align: center;
    margin: 50px 0px;
}

.marketing-main-header_button-primary {
    background-color: white;
    background-size: 150px 100px;
    font-size: 16px;
    border-color: transparent;
    color: #4834D4;
    font-family: Roboto Regular;
    width: 373px;
    height: 92px;
}

.marketing-main-header_button {
    margin-top: 50px;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js"></script>

<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>

<div class="container-fluid marketing-main-header">
        <div class="marketing-main-header_banner">
        <div class="sample">
            <nav class="navbar navbar-expand-lg navbar-light">
                <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav"
                    aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
                    <span class="navbar-toggler-icon"></span>
                </button>
                <div class="collapse navbar-collapse" id="navbarNav">
                    <ul class="navbar-nav ml-auto marketing-navbar">
                        <li class="marketing-navbar_items  nav-item">
                            <a class="marketing-nav-link nav-link" href="#">Dla kogo </a>
                        </li>
                        <li class="marketing-navbar_items nav-item">
                            <a class="marketing-nav-link nav-link" href="#">Agenda</a>
                        </li>
                        <li class="marketing-navbar_items nav-item">
                            <a class="marketing-nav-link nav-link" href="#">Prowadzacy</a>
                        </li>
                        <li class="marketing-navbar_items nav-item">
                            <a class=" marketing-nav-link nav-link " href="#">Faq</a>
                        </li>
                        <li class="marketing-navbar_items nav-item">
                            <a class="marketing-nav-link nav-link " href="#">Kontakt</a>
                        </li>
                        <li class="marketing-navbar_items nav-item">
                            <a class="marketing-nav-link nav-link " href="#">Kompetencje</a>
                        </li>
                    </ul>
                </div>
            </nav>

            <div class="marketing-main-header_details">
                    <div class="marketing-main-header_logo">
                        <img src="https://thumb.ibb.co/hPrhZp/logo_mib.png">
                    </div>
                    <div class="marketing-main-header_title">
                        <h1>SZKOLENIA</h1>
                    </div>
                    <div class="marketing-main-header_description">
                        <p>Lorem ipsum dolor sit amet, an pro dicta maiorum recusabo.</p>
                    </div>
                    <div class="marketing-main-header_sub-description">
                        <p>Lorem ipsum dolor sit amet, an pro dicta maiorum recusabo.</p>
                    </div>

                    <div class="marketing-main-header_button">
                        <button type="button" class="marketing-main-header_button-primary">Poznaj Agende</button>
                    </div>
                </div>
            </div>
        </div>
    </div>

Is there a way to make sure the text is not affected by the opacity set on the header background image?

Answer №1

Create a `:before` pseudo-element on the class `.marketing-navbar_items`. By doing this, you can ensure that it does not affect the opacity of its child elements (since there are none).

/* Main header for marketing business */
.marketing-navbar_items {
    font-family: Helvetica Neue;
    font-size: 30px;
    font-weight: normal;
    color: #FFFFFF;
}

.marketing-main-header_banner, .marketing-main-header_banner:before {
    background-image: url("https://svgshare.com/i/8KR.svg");
    background-size: auto 1199px;
    background-repeat: no-repeat;
    background-position: center -250px;
    height: 949px;
}

.marketing-main-header_banner {
    position: relative;
}

.marketing-main-header_banner:before {
    content: "";
    display: block;
    width: 100%;
    position: absolute;
    top: 50px;
    opacity: 0.5;
}

.marketing-main-header_details {

    display: flex;
    justify-content: center;
    flex-direction: column;
    align-items: center;
    margin-top: 30px;
}

.marketing-main-header_description p {
    font-size: 30px;
    font-family: HeaderFont;
    color: white;
    /* width: 55%; */
    text-align: center;
    margin: 50px 0px;
}

.marketing-main-header_button-primary {
    background-color: white;
    background-size: 150px 100px;
    font-size: 16px;
    border-color: transparent;
    color: #4834D4;
    font-family: Roboto Regular;
    width: 373px;
    height: 92px;

}

.marketing-main-header_button {
    margin-top: 50px;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js"></script>

<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>

<div class="container-fluid marketing-main-header">
        <div class="marketing-main-header_banner">
        <div class="sample">
            <nav class="navbar navbar-expand-lg navbar-light">
                <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav"
                    aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
                    <span class="navbar-toggler-icon"></span>
                </button>
                <div class="collapse navbar-collapse" id="navbarNav">
                    <ul class="navbar-nav ml-auto marketing-navbar">
                        <li class="marketing-navbar_items  nav-item">
                            <a class="marketing-nav-link nav-link" href="#">For Whom </a>
                        </li>
                        <li class="marketing-navbar_items nav-item">
                            <a class="marketing-nav-link nav-link" href="#">Agenda</a>
                        </li>
                        <li class="marketing-navbar_items nav-item">
                            <a class="marketing-nav-link nav-link" href="#">Speakers</a>
                        </li>
                        <li class="marketing-navbar_items nav-item">
                            <a class=" marketing-nav-link nav-link " href="#">FAQ</a>
                        </li>
                        <li class="marketing-navbar_items nav-item">
                            <a class="marketing-nav-link nav-link " href="#">Contact</a>
                        </li>
                        <li class="marketing-navbar_items nav-item">
                            <a class="marketing-nav-link nav-link " href="#">Competencies</a>
                        </li>
                    </ul>
                </div>
            </nav>


            <div class="marketing-main-header_details">
                <div class="marketing-main-header_logo">
                    <img src="https://thumb.ibb.co/hPrhZp/logo_mib.png">
                </div>
                <div class="marketing-main-header_title">
                    <h1>TRAININGS</h1>
                </div>
                <div class="marketing-main-header_description">
                    <p>Lorem ipsum dolor sit amet, consetetur sadipscing elitr.</p>
                </div>
                <div class="marketing-main-header_sub-description">
                    <p>Lorem ipsum dolor sit amet, consetetur sadipscing elitr.</p>
                </div>

                <div class="marketing-main-header_button">
                    <button type="button" class="marketing-main-header_button-primary">Explore Schedule</button>
                </div>
            </div>
            </div>
        </div>
    </div>

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

Find the position of an HTML5 canvas element within a webpage

I am currently facing an issue with a canvas within another canvas. <canvas id ='canvas2' height="718" width="1316"></canvas> The CSS for this canvas is as follows: #canvas2{ position:absolute; width :95%; height:90%; top:5%; lef ...

Design a circular text element using Tailwind CSS

Just starting out as a web developer and running into some issues with Tailwind CSS. Here's what I'm trying to achieve: https://ibb.co/KL8cDR2 This is the code I have right now: <div class="w-1/2 h-10 rounded-full bg-gray-400" style ...

issue with excessive content overflow

I'm working with a div structure where the outer div has the following CSS properties: position: relative; overflow: hidden; min-heigth: 450px; Inside this outer div, there is another div with the following CSS properties: position: absolute; top: ...

Is there a way to align the image next to the form and ensure they are both the same size?

I've been struggling to resize the image to match the form size, but I can't seem to get it right. Can anyone provide me with some guidance on this issue? I have obtained this contact form from a website that I plan to modify slightly, but I need ...

What is the best way to choose the first parent element that includes a specific class within it?

I am searching for a method to identify the initial parent element that includes another element with a specified class within it. For instance: <div class="wrapper"> <div class="item"> <div class="inner-eleme ...

switch from material ui lists on/off

Trying to learn React through coding, I've encountered an issue with displaying the 'StarBorder' icon next to folders when clicked. Currently, clicking on any folder displays the 'StarBorder' icon for all folders. Any tips on how t ...

Can you explain the significance of the "row" class in Bootstrap, how it differs from containers, and how it interacts with col-***-*?

I've been browsing through the guide found at http://getbootstrap.com/css/ and I'm having trouble grasping the purpose of the "row" class. I experimented with some examples provided in the guide like: <div class="row"> <div class="c ...

How to create a responsive image that appears over a button when hovering in Bootstrap?

My goal is to display an image over a button when hovering. I've tried adding the .img-responsive class in Bootstrap while including the image in the HTML, but it's not working as expected with my current method of loading images. The buttons the ...

utilizing javascript once form elements are dynamically inserted

While dynamically constructing form elements, I encountered an issue with generating unique IDs when the form is submitted. Everything works fine except for the JavaScript function responsible for populating the year in a dropdown selection. The issue ari ...

What causes Chrome Extension Images to appear broken when they are inserted into the DOM?

Currently working on a Chrome extension, I am attempting to insert a div with a background image into the DOM using a content script. The CSS is loading correctly, and upon inspecting the Developer Tools, the image URL appears to be correct. $('.clos ...

Retrieve the initial entry from a Container for every row in the Table

I'm facing an issue with a table I have on my website. Here is the structure: <table id="fieldContainer"> <tr><td><input id="input1"></td><td><input id="input2"></td></tr> <tr><td>< ...

What is the best way to ensure DIVs or SPANs have a fixed width with their content while also utilizing the remaining available space with white space?

My current setup is similar to the following. <div width="100%"> <span width="33%">FIRSTNAME</span> <span width="33%">|LASTNAME</span> <span width="33%">|CITY</span> </div> When executed, it appears a ...

Is it possible to implement a custom icon for pagination in Material UI?

Can I use a custom icon for pagination in material ui? Find more information on Material UI Pagination in the official documentation here, and check out the CodeSandbox Demo here I am interested in changing the default left and right chevron icons for na ...

How about creating a fresh variable in Assemble or merging two comparison helpers together?

Is it possible to create a new variable within a partial in Assemble (assemble.io) or combine two comparison helpers? For example: {#is somevar "yes" || anothervar "no"} In my partial, I have HTML that should only display if one of two different variable ...

Tips for adjusting the div style when resizing the browser

As I work on a script, I encounter an issue where the style of a div should change when it becomes larger due to resizing. Even though I have come up with a solution for this problem, there are still some inconsistencies. Sometimes the width is reported a ...

Quick trick to strip decimal points from prices with jquery

Is there a way to remove the decimal point from the price on my website? This is what my HTML looks like: <span id="product-price-4432" data-price-amount="399" data-price-type="finalPrice" class="price-wrapper " itemprop="price"> <span class="p ...

Tips for creating animations with JavaScript on a webpage

I created a navigation bar for practice and attempted to show or hide its content only when its title is clicked. I successfully toggled a hidden class on and off, but I also wanted it to transition and slide down instead of just appearing suddenly. Unfort ...

Using Thymeleaf in Spring MVC to link a .css file to your webpage

I am currently working on a project using spring MVC and Thymeleaf. I have encountered an issue regarding how to reference my CSS files within my folder structure: src main webapp resources myCssFolder myCssFile.css web-inf ...

Troubleshooting jQuery: Unable to refresh the webpage

I have a PHP page that contains a form, checkboxes, and a submit button. I added an if statement to execute a PHP script I created when the button is clicked, which deletes certain values from the selected rows. The button functions properly and changes s ...

Discover the way to create an HTML button with a mesmerizing transparent effect

For my website creation using Dreamweaver, I came up with the idea of utilizing Photoshop to design backgrounds. The reasoning behind this choice was that if I needed to modify button names at any point, I could simply edit the code and make the necessary ...