Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Z-index not working as expected

Tags:

html

css

z-index

I am developing a webpage and I am having problems with z-index not working as expected. My structure looks like this:

<div class="mainWrapper">
    <div class="overlay"></div>
    <div class="main">
        <div class="content1">
            content goes here
        </div>
    </div>
</div>

In overlay, I have a picture that should be above the main-class, but under the content-class. I've tried simply adding different z-indexes, but it does not seems to work. How can I solve this problem? Does this happen because the overlay-div is outside the other divs?

like image 357
OptimusCrime Avatar asked Nov 13 '22 15:11

OptimusCrime


1 Answers

<style>
.mainWrapper{ position:relative; }
.overlay{ position:absolute; }
.main{ position:absolute; }
.content1{ position:absolute; }
</style>
<div class="mainWrapper">
    <div class="main"></div>
    <div class="overlay"></div>        
    <div class="content1">
        content goes here
    </div>
</div>

With absolute positioning, Items will get layered in the order they added to the page. So here, main will be the bottom layer, then overlay on top of that, then content1 above that.

like image 81
Senica Gonzalez Avatar answered Dec 10 '22 00:12

Senica Gonzalez