Игра с z-индексом rel и rel1 изменит позицию в стеке, но fx никогда не будет поверх них даже с более высоким z-index, если только он не будет перемещен поверх rel в DOM. Почему это происходит ?
.fx {
position: fixed;
height: 30px;
width: 30px;
background-color: pink;
margin-top: 60px;
margin-left: 30px;
z-index: 10000;
}
.rel {
z-index: 7;
position: relative;
height: 500px;
width: 200px;
background-color: red;
margin-top: 30px;
}
.rel1 {
z-index: 6;
position: relative;
height: 500px;
width: 100px;
background-color: black;
margin-top: -300px;
}<div class = "rel">
</div>
<div class = "rel1">
</div>
<div class = "fx">
</div>





Он соответствует правилам стека, но его позиция еще не установлена, вы должны установить позицию вверху: 0px;
Вам необходимо указать атрибуты позиции .fx:
Обычно комбинация либо top, либо bottom, плюс, либо left, либо right.
Рабочий пример:
.fx {
position: fixed;
top: 0;
left: 0;
height: 30px;
width: 30px;
background-color: pink;
margin-top: 60px;
margin-left: 30px;
z-index: 10000;
}
.rel {
z-index: 7;
position: relative;
height: 500px;
width: 200px;
background-color: red;
margin-top: 30px;
}
.rel1 {
z-index: 6;
position: relative;
height: 500px;
width: 100px;
background-color: black;
margin-top: -300px;
}<div class = "rel">
</div>
<div class = "rel1">
</div>
<div class = "fx">
</div>Как говорит МДН оposition: fixed:
Its final position is determined by the values of top, right, bottom, and left.
Итак, ваш код будет выглядеть так:
.fx {
position: fixed;
height: 30px;
width: 30px;
background-color: pink;
margin-top: 60px;
margin-left: 30px;
z-index: 10000;
top: 20px;
left: 10px;
}
.rel {
z-index: 7;
position: relative;
height: 500px;
width: 200px;
background-color: red;
margin-top: 30px;
}
.rel1 {
z-index: 6;
position: relative;
height: 500px;
width: 100px;
background-color: black;
margin-top: -300px;
}<div class = "rel">
</div>
<div class = "rel1">
</div>
<div class = "fx">
</div>