In the snippet below I expect .fixed
to be fixed relatively to the body
. It works fine - element is fixed, until transform
is applied to .wrapper
on hover - .fixed
element now movew with parent container. Why is that happening and how do I avoid this?
.wrapper {
background: salmon;
height: 300px;
margin: 30vh;
transition: .4s;
}
.wrapper:hover {
transform: translateX(30px) translateY(10px);
}
.fixed {
font-family: Arial;
color: white;
text-transform: uppercase;
font-size: 20px;
position: fixed;
top: 50%;
left: 50%;
transform: translateY(-50%) translateX(-50%);
}
<div class="wrapper">
<div class="fixed">
fixed
</div>
</div>