This example shows how to use the translate
property to move an element in three axes. The first box is moved along the X axis and the second box is moved along the X and Y axes. The third box is moved along the X, Y and Z axes and has the appearance of moving toward the viewer because of the addition of perspective
to the parent element.
HTML
<div class="wrapper">
<div id="box1">translate X</div>
<div id="box2">translate X,Y</div>
<div id="box3">translate X,Y,Z</div>
</div>
CSS
.wrapper {
perspective: 100px;
display: inline-flex;
gap: 1em;
}
.wrapper > div {
width: 7em;
line-height: 7em;
text-align: center;
transition: 0.5s ease-in-out;
border: 3px dotted;
}
#box1:hover {
translate: 20px;
}
#box2:hover {
translate: 20px 20px;
}
#box3:hover {
translate: 5px 5px 30px;
}
Result