css伪元素实现按钮边框动效

这篇博客介绍了如何通过CSS伪元素和渐变来创建一个边框动画效果。作者提供了一段SCSS代码示例,该代码应用于按钮元素,使其在鼠标悬停时呈现出从四个角向中心扩展的动画效果。这是一个关于前端开发,特别是CSS技巧和动画效果的分享。
摘要由CSDN通过智能技术生成

wx公众号:XQ前端

1. 效果预览

在这里插入图片描述

2. 源码

我们通过伪元素和渐变实现以上效果

// 边框动画
@mixin border-animate() {
position: relative;
border-color: #24AFFF;
color: #24AFFF;
opacity: 0.8;
background: #3c3d45;
&:before, &:after {
  content: '';
  display: block;
  width: 0;
  height: 0;
  position: absolute;
  border-style: solid;
  border-width: 2px;
  border-image-source: linear-gradient(-45deg, #0d76ec 0%, #00f0ff 100%);
  border-image-slice: 1;
}
&:before {
  top: 0;
  left: 0;
  opacify: 0;
  border-bottom: none;
  border-left: none;
  transition: width 0.1s ease-out 0.3s, height 0.1s ease-out 0.2s, opacity 0.2s ease-out 0.2s;
}
&:after {
  bottom: 0;
  right: 0;
  opacity: 0;
  border-right: none;
  border-top: none;
  transition: width 0.1s ease-out 0.1s,height 0.1s ease-out 0s, opacity 0.4s;
}
&:hover {
  &:before, &:after{
    opacity: 1;
    width: 100%;
    height: 100%;
  }
  &:before {
    opacity: 1;
    width: 100%;
    height: 100%;
    transition: width 0.1s ease-in 0s,height 0.1s ease-in 0.1s, opacity 0.4s;
  }
  &:after {
    opacity: 1;
    width: 100%;
    height: 100%;
    transition: width 0.1s ease-in 0.2s,height 0.1s ease-in 0.3s, opacity 0.4s;
  }
}
}

.q-btn-wrap{
background: #3c3d45;
padding: 33px;
width: 110px;
.q-button{
  cursor: pointer;
  border: none;
  display: inline-block;
  width: 100px;
  height: 30px;
  color: #ff4b4b;
  @include border-animate()
}
}

欢迎大家关注 wx公众号:XQ前端
每天分享一点前端小知识

在这里插入图片描述

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值