problem with z-index and background image overlap

I'm attempting to overlay a .header-content div, containing the website content, on top of another .header-bg div, which has only a background cover and a set height using z-index.

When I change the .header-bg to position:absolute, the background image disappears, but the .header-content is placed correctly. If I change it to position: relative, the background appears, but the content is positioned beneath the background image instead of on top.

Has anyone encountered this issue before?

The HTML

<body>
        <div class="header header-bg"></div>
        <div class="header home-header">

            <div class="header-content">
                <a href="#" class="logo txtimg" title="Back to Homepage">LOGO</a>
                <p class="slogan">SLOGAN</p>
            </div>

            <div class="header slider">
                <div class="slider-navbar">
                </div>
            </div>

            <navbar class="menu home-menu">
                test
            </navbar>
        </div>
    </body>

The CSS

.logo{
    background: url(img/logo.png) no-repeat;
    height: 96px;
    width: 402px;
    display: block;
    margin: 0 auto;
    padding-bottom: 1em;
}

.slogan {
    color: #fff;
    text-align: center;
    width: 940px;
    margin: 0 auto;
    margin-top: 10px;
}

/*.css-img-replacement*/
.txtimg {
    text-indent: -9999em;
    overflow: hidden;
}

.header-bg{
    background: #bf1718 url(img/header_bg.png) no-repeat 50% !important;
    background-size: cover;
    z-index:0;
    position: relative;
}

.header {
    height:588px;
}

.header-content {
    padding: 1em 0;
    z-index: 900;
    position: absolute;
}

(I apologize for any English errors, as I am French. I hope you understand nevertheless)

Answer №1

Make sure to assign a value to the top position of .header-content:

.header-content {
    padding: 1em 0;
    z-index: 900;
    position: absolute;
    top: 0;
}

When no specific values for top, right, bottom, or left positioning are added, an absolute element will maintain its static position. The static position refers to where the element would naturally be placed within the flow of the page without any further positioning properties specified.

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

The hyperlink in the mobile version of the mega menu is unresponsive in HTML

I am encountering an issue with the navigation menu on my Laravel website. The menu links work correctly on the desktop version, but none of the anchor tag links are functioning properly on the mobile version. HTML <div class="menu-container"> < ...

When BeautifulSoup is utilized, HTML tags are stripped of their opening and closing components

Encountered a problem while using BeautifulSoup to scrape data from the website www.basketball-reference.com. Although I have used BeautifulSoup successfully on Bballreference before, I am puzzled by what is happening this time around (admittedly, I am sti ...

Combining two forms into one PHP page, but intending to submit only a single form

I'm facing an issue on my page where I have both a sign-in and a sign-up form. Whenever I click on either the sign-in or sign-up button, it always ends up submitting the sign-up form. What am I doing wrong? Here's the PHP code snippet: if($_SE ...

Is there a way to modify the appearance of a text box to suit individual preferences?

Is it possible to alter the shape of a text box, creating a rectangle with a portion removed from one side? I have included an example image for reference. https://i.sstatic.net/oNyum.png I came across clip-path: polygon in CSS, but it seems to only accep ...

Display the toggle button for expanding/collapsing text only when the length of the string exceeds 50 characters

Is there a way to only show a "read more/less" button in a table if the content exceeds 50 characters? The table contains a mix of content, some short announcements with about 10 characters and others with over 100. <div class="col"> <span ng-c ...

What is the best way to implement two distinct global CSS styles for separate pages in Next.js?

I'm looking to give my website a fresh look by creating two different global CSS styles. Is it possible to use one CSS style for the old pages and another for the new pages? ...

Save hyperlinks provided by users within the text

Users have the ability to create a post and leave a comment. I am aiming to give my users the option to include a hyperlink in their comment, such as: "This is a comment where aboutme is a hyperlink." I am unsure of how to store this hyperlink. Currently, ...

Navigating Dynamically between tabs - A How-to Guide

I am working on a mat-tab Angular app where I need to dynamically generate links and transfer them to a navLinks object. Despite ensuring that the concatenation is correct, it seems like my approach is not working as expected. Here's a glimpse of what ...

I'm having trouble getting a response from the user.php file in my login system

I am trying to create a login system using ajax and pdo with a button as the submitter. The issue I am facing is that when I click the button to execute, nothing happens. There are no errors in the console. I can see in the network tab that it sends the us ...

Include a character on the right side without shifting the text to the left

Below is the HTML code I am currently working with: <div class="last_img"> <p>Galutinė žetono išvaizda:</p> <span class="zetin11">A</span> <span class="zetin12">A</span> < ...

EaselJS - Utilizing multiple canvases with varying frame rates

Currently, I am exploring EaselJS by creating two animation instances using sprite sheets on two separate canvases positioned at different locations but with the same z-index. The issue I am facing is that these instances are not layered properly. My setup ...

Is there a way to arrange my bootstrap navigation tabs vertically on my mobile device?

I have a group of five bootstrap navigation tabs that are evenly spaced and visually appealing on desktop screens. However, when viewed on a mobile device, the text within the tabs becomes cramped together. How can I make the tabs stack vertically on mobil ...

Storing user input from HTML forms in a MySQL database table with PDO

Currently, I am in the process of developing a webpage that will contain multiple forms for users to fill out and submit. Once submitted, PHP will be responsible for executing a query to insert all the data into the table within their respective fields. I ...

I am struggling to understand why clicking this button is not successfully submitting the form to Google Sheets

I am facing an issue with my Google Sheet setup that collects form data from my website. The problem is, I am unable to link the event to a button that already exists ('CompleteOrder'). Strangely, it works perfectly fine if I add a new button: & ...

Insert a new class within the container div

I am looking to insert a 'disabled' class within a parent div named 'anchorxx' https://i.sstatic.net/3KRMQ.png The disabled class div can be located anywhere within the anchorXX divs Is it achievable using jquery? I am unsure how to ...

Nested scrolling bars within each other

Currently, I am importing photos from a Facebook page and displaying them on my jQuery mobile webpage using the photoSwipe plugin. However, there seems to be an issue with the final appearance of the images. Pay attention to the image where the red arrow ...

What is the best way to prevent certain bootstrap classes from being applied across all elements?

After testing my HTML and CSS code on my local computer, it looks perfect. However, when I upload it to a server, the appearance changes. You can see it in action here: . The issue seems to be related to some bootstrap classes being activated differently ...

How to conceal 'subnavigation' elements within Buddypress

Hey everyone, I've been looking into how to hide subnav items in a drop-down list. Can this be achieved using just CSS or will I need to write some code for it to work properly? My main goal is to have the sub nav items appear when the user hovers ove ...

Leveraging CSS nth-child selector in conjunction with ngFor in angular2

Looking for a way to style odd and even rows differently in my dynamically generated table using ngFor directive in angular2. *ngIf="AreThereMyOldMessages" *ngFor="let oldm of MyOldMessages;let i=index" *ngIf="AreThereMyNe ...

Switching between three div elements along with two icons can be done by using toggle functionality

Is there a way to make the icon change back when clicked again without making major changes to the existing code? Looking for suggestions on how to achieve this functionality. function myFunction() { var element = document.getElementById("demo"); el ...