Div fixed behind the others

0
Hello, the first div of my site has the fixed position ( position:fixed ), and when I roll down, it stays behind the other elements, like images and etc. Does not work even if I put position:absolute or position:sticky , can anyone help me?

    
asked by anonymous 29.09.2018 / 04:30

2 answers

0

The natural ordering of the stacking elements is that the ones previously inserted into the DOM tree are below those inserted later. It's the stacking order .

As a result, the first% fixed% you set will stay below the later ones when scrolling. To change this, there is the div property that changes the stacking order of elements, and can cause one element inserted before to override another inserted later.

Since the DOM tree can have multiple levels of nodes, each level gets a z-index according to its position, 1, 2, 3, and so on, you can declare z-index to its z-index so that it guarantees that it will override the others by assigning a sufficiently high value, and this value may depend on the structure of your project.

But for simplicity, a value of 9 may already be enough. Add in your CSS a div to your z-index: 9 :

#minhaDiv{
   z-index: 9;
}
    
29.09.2018 / 05:37
0

You can use z-index to set the order of elements. In this case, you want to overlap all elements with your div, use the following:

    #suadiv{ 
    z-index: 99; /* 99 para que não tenha duvidas sobre os níveis de sobreposição */
}

You can check out more about the z-index property directly on the W3Schools website Clicking here . / p>     

04.10.2018 / 20:06