I'm trying to replicate the button animation seen on this page:
Where the border changes color from the top left to bottom right.
I can get the left and the top to animate correctly, but then instead of the lines continuing down and across the bottom, a box expands out for the bottom and right. Can anyone see what I'm doing wrong.
I have attached my attempt at the code below. HTML and CSS.
.hover-effect-button-container-yellow {
max-width:150px;
position:relative;
}
.hover-effect-button-yellow {
text-align:center;
border:1px solid white;
font-family: "Muli", sans-serif;
font-size: 15px;
font-weight: 500;
line-height: 25.5px;
padding-bottom: 10px;
padding-left: 25px;
padding-right: 24px;
padding-top: 10px;
}
.hover-effect-button-yellow:before {
box-sizing: inherit;
content: "";
position: absolute;
width: 0;
height: 0;
}
.hover-effect-button-yellow:after {
box-sizing: inherit;
content: "";
position: absolute;
width: 0;
height: 0;
}
.hover-effect-button-yellow:before {
border-top: 1px solid white;
border-left: 1px solid white;
top: 0;
left: 0;
}
.hover-effect-button-yellow:after {
border-right:1px solid white;
border-bottom:1px solid white;
top: 0;
left:0;
}
.hover-effect-button-yellow:hover:before {
width:100%;
height:100%;
border-top-color: red;
border-left-color: red;
transition: height 1s ease-out, width 1s ease-out;
}
.hover-effect-button-yellow:hover:after {
width:100%;
height:100%;
border-bottom-color: red;
border-right-color: red;
transition: height 1s ease-out 1s, width 1s ease-out 1s;
}
<div >
<div >
<a href="#">CLICK HERE</a>
</div>
</div>
CodePudding user response:
You need to give to <a>
and give css to it.
You need to add whole border in ::before and ::after of the button:
.button::before, .button::after {
border: 1px solid transparent;
}
and change the top right left bottom borders on hover of ::before and ::after selectors of button; also change the transition as shown:
.button:hover::before {
border-top-color: #0076b6;
border-right-color: #0076b6;
transition: width 0.25s ease-out, height 0.25s ease-out 0.25s;
}
.button:hover::after {
border-bottom-color: #0076b6;
border-left-color: #0076b6;
transition: height 0.25s ease-out, width 0.25s ease-out 0.25s;
}
Please find updated css and html below:
.button {
background: none;
border: 0;
box-sizing: border-box;
padding: 0.9rem 2rem;
box-shadow: inset 0 0 0 1px #fff;
color: #000000;
text-transform: uppercase;
font-family: "ff-meta-web-pro","Helvetica Neue",Helvetica,Roboto,Arial,sans-serif;
font-weight: 400;
letter-spacing: 0.025em;
position: relative;
vertical-align: middle;
transition: color 0.25s;
display: inline-block;
text-decoration: none;
}
.button::before {
top: 0;
left: 0;
}
.button::before, .button::after {
box-sizing: inherit;
content: "";
position: absolute;
width: 0;
height: 0;
border: 1px solid transparent;
}
.button::after {
top: 0;
left: 0;
bottom: 0;
right: 0;
}
.button:hover {
outline-width: 0;
text-decoration: none;
}
.button:hover::before {
border-top-color: #0076b6;
border-right-color: #0076b6;
transition: width 0.25s ease-out, height 0.25s ease-out 0.25s;
}
.hover-effect-button-container-yellow {
padding: 10px;
background: pink;
}
.button:hover::before, .button:hover::after {
width: 100%;
height: 100%;
}
.button:hover::after {
border-bottom-color: #0076b6;
border-left-color: #0076b6;
transition: height 0.25s ease-out, width 0.25s ease-out 0.25s;
}
<div >
<div >
<a href="https://beedie.ca/industrial/">Learn More</a>
</div>
</div>