纠结于CSS按钮动画



我想复制这个页面上看到的按钮动画:

https://www.beedie.ca/

边框从左上到右下的颜色变化。

我可以让左侧和顶部的动画正确,但然后不是线条继续向下并穿过底部,而是底部和右侧的一个框展开。有谁能看出我做错了什么吗?

我附上了我对下面代码的尝试。HTML和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 class="hover-effect-button-container-yellow">
<div class="hover-effect-button-yellow"> 
<a href="#">CLICK HERE</a>
</div>
</div>

你需要给class="button"><a>添加css

你需要在::之前添加整个边框:>按钮的位置:

.button::before, .button::after {
border: 1px solid transparent;
}

并更改按钮选择器::before和::after的上下边框;还可以更改过渡,如下所示:

.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;
}

请看下面更新的css和html:

.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 class="hover-effect-button-container-yellow">
<div class="hover-effect-button-yellow"> 
<a class="button" href="https://beedie.ca/industrial/">Learn More</a>
</div>
</div>

相关内容

  • 没有找到相关文章

最新更新