In order for Z-index to work properly you must comply with certain conditions , it is mainly used in the following way:
<main class="padre">
<div class="hermano uno">
<img class="hijo" src=".png"/>
</div>
<div class="hermano dos">
</div>
</main>
Mainly for the z-index layers to work, they must be at the same level of kinship, for example with the previous code the z-index will work with the two "brothers" , but it will not work between the child and the brother two . The other thing that needs to be added is position: relative , fixed or absolute as the case may be. Then the conditions, formally written would be:
- Elements placed in layers, must be at the same hierarchy level in the html layout.
- They must have declared position different from the default that is static .
- Items nested in a lower or upper layer will inherit the layer declared in their container, but will never overlap the level declared to the container ancestor or the "sibling" elements to the parent .
The most typical error is to believe that this will work in css, like this:
.hermano, .hijo {position: relative;}
.hijo{z-index: 1; }
.hermano.dos {z-index: 9999}
If the image "son" is greater than the height of "brother one" it will overlap "brother two", so when wanting to correct this one tries to use a z-index in "brother two" very high to try without correcting this, but as I mentioned, not being at the same level, the son and brother two, this will never work, in this case, we must declare the z-index in the two brothers and increase the value in which you will overcome , like this:
.hermano, .hijo {position: relative;}
.hermano.uno {z-index: 1}
.hijo{}
.hermano.dos {z-index: 2}
I hope it has been clear, or that indeed is the error that is presented to you, the truth is that as many have commented on the code put in the question, it does not reproduce the error and it is very difficult to know how to help you in a better way. Successes!