I’d like my div to move when hovering an existing div
.divToMove {
transform: translateY(-100%);
}
@keyframes slideIn {
from {
transform: translateY(-100%);
}
to {
transform: translateY(-35%);
}
}
.divToHover:hover .divToMove {
animation: slideIn 0.5s forwards;
}
the div is "stuck" where it originally was placed, I’d like it to transition from -100% in Y to -35
2
Answers
Adjacent sibling combinator –
+
in CSS – MDN DocsYou can’t directly modify other element’s styling on hover. You need to make use of CSS Combinators
Here, I have used General Sibling Selector (~), which selects all
.divToMove
elements that are next siblings of.divToHover
.If
.divToMove
and.divToHover
remain adjacent, you can also use the+
combinator.