I have a css arrow that points from right to left. I have the arrow first and then the text. I am trying to achieve the following transition when hovering over: Hover over, the arrow on the left disappears and appears on the right after the text. How do I go about achieving that effect that the arrow appears on the right on hover?
I am trying to achieve this effect but in the opposite direction
body {
background: black;
}
.the-arrow {
width: 64px;
transition: all 0.2s;
transform: rotate(180deg);
}
.the-arrow.-left {
position: absolute;
top: 60%;
right: 0;
}
.the-arrow.-left .shaft {
width: 0;
background-color: #999;
}
.the-arrow.-left .shaft:before,
.the-arrow.-left .shaft:after {
width: 0;
background-color: #999;
}
.the-arrow.-left .shaft:before {
-webkit-transform: rotate(0);
transform: rotate(0);
}
.the-arrow.-left .shaft:after {
-webkit-transform: rotate(0);
transform: rotate(0);
}
.the-arrow.-right {
top: 3px;
}
.the-arrow.-right .shaft {
width: 64px;
transition-delay: 0.2s;
}
.the-arrow.-right .shaft:before,
.the-arrow.-right>.shaft:after {
width: 8px;
transition-delay: 0.3s;
transition: all 0.5s;
}
.the-arrow.-right .shaft:before {
-webkit-transform: rotate(40deg);
transform: rotate(40deg);
}
.the-arrow.-right .shaft:after {
-webkit-transform: rotate(-40deg);
transform: rotate(-40deg);
}
.the-arrow .shaft {
background-color: #fff;
display: block;
height: 1px;
position: relative;
transition: all 0.2s;
transition-delay: 0;
will-change: transform;
}
.the-arrow .shaft:before,
.the-arrow .shaft:after {
background-color: #fff;
content: '';
display: block;
height: 1px;
position: absolute;
top: 0;
right: 0;
transition: all 0.2s;
transition-delay: 0;
}
.the-arrow .shaft:before {
-webkit-transform-origin: top right;
transform-origin: top right;
}
.the-arrow .shaft:after {
-webkit-transform-origin: bottom right;
transform-origin: bottom right;
}
.animated-arrow {
display: inline-block;
color: #fff;
font-size: 12px;
text-decoration: none;
position: relative;
transition: all 0.2s;
}
.animated-arrow:hover {
color: #eaeaea;
}
.animated-arrow:hover .the-arrow.-left .shaft {
width: 64px;
transition-delay: 0.1s;
background-color: #eaeaea;
}
.animated-arrow:hover .the-arrow.-left .shaft:before,
.animated-arrow:hover .the-arrow.-left .shaft:after {
width: 8px;
transition-delay: 0.1s;
background-color: #eaeaea;
}
.animated-arrow:hover .the-arrow.-left .shaft:before {
-webkit-transform: rotate(40deg);
transform: rotate(40deg);
}
.animated-arrow:hover .the-arrow.-left .shaft:after {
-webkit-transform: rotate(-40deg);
transform: rotate(-40deg);
}
.animated-arrow:hover .main {
-webkit-transform: translateX(80px);
transform: translateX(80px);
}
.animated-arrow:hover .main .the-arrow.-right .shaft {
width: 0;
-webkit-transform: translateX(200%);
transform: translateX(200%);
transition-delay: 0;
}
.animated-arrow:hover .main .the-arrow.-right .shaft:before,
.animated-arrow:hover .main .the-arrow.-right .shaft:after {
width: 0;
transition-delay: 0;
transition: all 0.1s;
}
.animated-arrow:hover .main .the-arrow.-right .shaft:before {
-webkit-transform: rotate(0);
transform: rotate(0);
}
.animated-arrow:hover .main .the-arrow.-right .shaft:after {
-webkit-transform: rotate(0);
transform: rotate(0);
}
.animated-arrow .main {
display: flex;
align-items: center;
transition: all 0.2s;
}
.animated-arrow .main .text {
margin: 0 0 0 16px;
line-height: 1;
font-family: 'Montserrat';
text-transform: uppercase;
}
.animated-arrow .main .the-arrow {
position: relative;
}
<div class="pivot-arrows-1" style="">
<a class="animated-arrow arrow-c-f" href="#">
<span class="main">
<span class="the-arrow -right">
<span class="shaft"></span>
</span>
<span class="text">
Some cool Text
</span>
</span>
<span class="the-arrow -left">
<span class="shaft"></span>
</span>
</a>
</div>
just for the fun to make it shorter with a single pseudo and transition
body {
background: black;
color:purple;
font-size:2em;
}
a {
color: #fff;
font-size: 12px;
text-decoration: none;
position: relative;/* to be the reference for the absolute pseudo */
display:inline-block;/* to size it and set horizontal margin */
vertical-align:middle;
background:black;
margin:0 68px;
padding:0 0.25em;
}
.animated-arrow::before {
content:'\0003c';/* the sign < to draw edge of the arrow */
font-size:16px;/* might need to be resized */
/*display:inline-block; if not absolute */
width:64px;/* that was your value, equal at the most to the margin of parent link */
background:linear-gradient(to bottom, transparent 50%,currentcolor 50%, currentcolor calc(50% + 1px) , transparent calc(50% + 1px));/* to draw the body arrow */
top:-0.15em;/* if needed */
position:absolute;/* , so coordonate are easier to set */
z-index:-1;/* let slide under the link */
right:100%;
transition: right 0.2s, transform 0.1s 0s;
}
.animated-arrow:hover::before {
right:-64px;
transform:scale(-1,1)
}
a+a {color:gold;}
<a class="animated-arrow arrow-c-f" href="#">Some cool Text</a> ⊛
<a class="animated-arrow arrow-c-f" href="#">Some cool Text of any length</a>
Using a single element
*{
box-sizing: border-box
}
body{padding: 4rem}
.arrow{
position: relative;
display:inline-block
}
.arrow:before,
.arrow:after{
content: "";
position: absolute;
top: 50%;
transition: all 0.2s;
}
.arrow:before{
right: 100%;
width:32px;
height:1px;
background: black;
}
.arrow:after{
width:12px;
height: 12px;
border-top: 1px solid black;
border-left: 1px solid black;
right: calc( 100% + 16px );
transform: rotate(-45deg);
margin-top: -6px;
}
.arrow:hover:before{
right: -32px
}
.arrow:hover:after{
transform: rotate(-45deg) scale(-1);
right: -32px;
}
<div class="arrow">some cool text</div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With