gpt4 book ai didi

css - 使用 CSS 在悬停时为圆形边框线设置动画

转载 作者:行者123 更新时间:2023-12-04 17:43:55 24 4
gpt4 key购买 nike

我正在尝试创建一个按钮悬停动画,其中的边框线是动画的。有谁知道是否可以使用 css 为圆 Angular 设置动画,或者我是否需要创建一个 svg 动画?请参阅下面的代码笔:

看笔 Button Border Hover Effect通过 Anton Lipovskoy ( @lipovskoy ) 在 CodePen .

@import url(https://fonts.googleapis.com/css?family=PT+Sans);
*, *:after, *:before {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
body{
font-family: 'PT Sans', sans-serif;
display: table;
width: 100%;
background: #004b60;
}
.container{
display: table-cell;
vertical-align: middle;
text-align: center;
height: 100vh;
}
button{
display: inline-block;
position: relative;
background: none;
border: none;
color: #fff;
font-size: 16px;
cursor: pointer;
margin: 10px 20px;
background: rgba(0, 210, 195, 1);
border-radius: 0.175rem;
-webkit-transition: all .5s ease-out;
-moz-transition: all .5s ease-out;
-o-transition: all .5s ease-out;
transition: all .5s ease-out;
}
span{
display: block;
padding: 15px 20px;
}
button::before, button::after{
content:"";
width: 0;
height: 1px;
position: absolute;
background: rgba(0, 210, 195, 1);
border-radius: 0.175rem;
transition: all 0.2s ease-out;
}

span::before, span::after{
content:"";
width:1px;
height:0;
position: absolute;
background: rgba(0, 210, 195, 1);
border-radius: 0.175rem;
transition: all 0.2s ease-out;
}
button:hover::before, button:hover::after{
width: 100%;
}
button:hover{
background: rgba(0, 210, 195, 0.1);
color:rgba(0, 210, 195, 1);
}
button:hover span::before, button:hover span::after{
height: 100%;
}

/*----- button 4 -----*/
.btn-4::after{
right:0;
bottom: 0;
transition-duration: 0.4s;

}
.btn-4 span::after{
right:0;
bottom: 0;
transition-duration: 0.2s;

}
.btn-4::before{
left: 0;
top: 0;
transition-duration: 0.4s;

}
.btn-4 span::before{
left: 0;
top: 0;
transition-duration: 0.2s;

}
<div class="container">
<button class="btn-4"><span>Hover Me</span></button>
</div>

最佳答案

我试着让它与 border-radiuswidth, height 一起工作。您可以将其边界半径更改为您的输入。也许它会帮助你得到你想要的。

@import url(https://fonts.googleapis.com/css?family=PT+Sans);
*, *:after, *:before {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
body{
font-family: 'PT Sans', sans-serif;
display: table;
width: 100%;
background: #004b60;
}
.container{
display: table-cell;
vertical-align: middle;
text-align: center;
height: 100vh;
}
button{
display: inline-block;
position: relative;
background: none;
border: none;
color: #fff;
font-size: 16px;
cursor: pointer;
margin: 10px 20px;
background: rgba(0, 210, 195, 1);
border-radius: 15px;
-webkit-transition: all .5s ease-out;
-moz-transition: all .5s ease-out;
-o-transition: all .5s ease-out;
transition: all .5s ease-out;
}
span{
display: block;
padding: 15px 20px;
}
button::before{
border-top:1px solid rgba(0,210, 195, 1);
border-radius:0px;
border-top-left-radius:0px;
border-top-right-radius:0;

border-bottom-right-radius:0;
border-bottom-left-radius:0;
}
button::after{
border-bottom:1px solid rgba(0,210, 195, 1);
border-radius:0px;
border-bottom-right-radius:0;
border-bottom-left-radius:0;
border-top-left-radius:0;
border-top-right-radius:0;

}
button::before, button::after{
content:"";
width: 0;
height: 0;
position: absolute;
/*background: rgba(0, 210, 195, 1);*/
border-radius: 15px;
transition: all 0.2s ease-out;
}
span::before {
border-left:1px solid rgba(0,210, 195, 1);
border-radius:0;

border-top-left-radius:0px;
border-top-right-radius:0;

border-bottom-right-radius:0;
border-bottom-left-radius:0px;
}
span::after {
border-right:1px solid rgba(0,210, 195, 1);
border-radius:0;

border-top-left-radius:0;
border-top-right-radius:0px;

border-bottom-right-radius:0px;
border-bottom-left-radius:0;
}

span::before, span::after{
content:"";
width:0;
height:0;
position: absolute;
/*background: rgba(0, 210, 195, 1);*/
border-radius: 15px;
transition: all 0.2s ease-out;
}
button:hover::before, button:hover::after{
width: 100%;
height:35px;
}

button:hover::before{
left: 0;
border-top-left-radius:15px;
}

button:hover::after{
right: 0;
border-bottom-right-radius:15px;
}
button:hover{
background: rgba(0, 210, 195, 0.1);
color:rgba(0, 210, 195, 1);
}
button:hover span::before, button:hover span::after{
height: 100%;
width:55px;
}
button:hover span::before{
top:0;
border-bottom-left-radius:15px;
}
button:hover span::after {
bottom:0;

border-top-right-radius:15px;
}

/*----- button 4 -----*/
.btn-4::after{
right:10px;
bottom: 0;
transition-duration: 0.4s;

}
.btn-4 span::after{
right:0;
bottom: 10px;
transition-duration: 0.2s;

}
.btn-4::before{
left: 10px;
top: 0;
transition-duration: 0.4s;

}
.btn-4 span::before{
left: 0;
top: 10px;
transition-duration: 0.2s;

}
<div class="container">
<button class="btn-4"><span>Hover Me</span></button>
</div>

也可以测试一下here

我仍然认为 SVG 是最有效的方法。

关于css - 使用 CSS 在悬停时为圆形边框线设置动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53084547/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com