I am trying to create a heading text with an arrow that translates when hovered over. Currently, it is achieved using position: absolute
, but I need to make it work with position: relative
.
Any suggestions on how this can be accomplished?
#container {
width: 130px;
border: 1px solid red;
padding: 10px;
}
#container h2:after {
transition: all 1s ease
}
#container:hover h2:after {
transform: translateX(30px);
transition: all 1s ease;
}
#container h2:after {
content: "->";
position: absolute;
/* It currently works with absolute positioning, but I want it to work with relative positioning. */
}
<div id="container">
<h2>Go to my website</h2>
</div>