Suppose the main container(not just the element) is labeled with a class named container
, you can simply include this rule to apply a higher z-index
to anything you hover over, not limited to the element itself:
.container *:hover {
z-index: 1;
}
For demonstration purposes, here's an example:
.container {
width: 200px;
counter-reset: box;
}
.row {
display: flex;
}
.box {
flex: 1;
height: 60px;
background-color: salmon;
margin: 0px 2px;
transition: all .5s;
counter-increment: box;
display: flex;
justify-content: center;
align-items: center;
}
.box::after {
content: counter(box);
color: white;
font-size: 1.5em;
}
.box:hover {
transform: scale(1.5);
background-color: steelblue;
}
.container *:hover {
z-index: 1;
}
<div class="container">
<div class="row">
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
</div>
<hr>
<div class="row">
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
</div>
<hr>
<div class="row">
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
</div>
</div>