温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

CSS3怎么实现逐渐发光的方格边框

发布时间:2023-01-04 09:21:47 阅读:135 作者:iii 栏目:开发技术
前端开发者测试专用服务器限时活动,0元免费领,库存有限,领完即止! 点击查看>>

本文小编为大家详细介绍“CSS3怎么实现逐渐发光的方格边框”,内容详细,步骤清晰,细节处理妥当,希望这篇“CSS3怎么实现逐渐发光的方格边框”文章能帮助大家解决疑惑,下面跟着小编的思路慢慢深入,一起来学习新知识吧。

效果图如下:

CSS3怎么实现逐渐发光的方格边框

HTML代码:

<div class="light">
 <img src="http://tva2.sinaimg.cn/crop.0.0.180.180.180/6830a53bjw8f2qo4xzc2zj20500500t0.jpg"/>
 <div class="light-inner">
  <p>前端开发博客</p>
  <p>关注前端开发</p>
 </div>
</div>

CSS代码:

.light{
 background#fff;
 width180px;
 height180px;
 margin100px auto;
 position: relative;
 text-align: center;
 color#333;
 transform:translate3d(0,0,0);

}
.light-inner{
 padding60px 30px 0;
 pointer-events: none;
 position: absolute;
 left0;
 top0;
 bottom0;
 right0;
 text-align: center;
 transition: background 0.35s;
 backface-visibility: hidden;
}
.light-inner:before.light-inner:after{
 display: block;
 content"";
 position: absolute;
 left30px;
 top30px;
 right30px;
 bottom30px;
 border1px solid #fff;
 opacity0;
 transition: opacity 0.35s, transform 0.35s;
}
.light-inner:before{
 border-left0;
 border-right0;
 transform:scaleX(0,1);
}
.light-inner:after{
 border-top0;
 border-bottom0;
 transformscaleY(1,0);
}
.light:hover .light-inner{
 background#458fd2
}
.light:hover .light-inner:before.light:hover .light-inner:after{
 opacity1;
 transformscale3d(1,1,1);
}

.light-inner p{
 transition: opacity .35s, transform 0.35s;
 transformtranslate3d(0,20px,0);
 color#fff;
 opacity0;
 line-height30px;
}
.light:hover .light-inner p{
 transformtranslate3d(0,0,0);
 opacity1;
}

实现步骤:

发光的方格,主要是通过.light-inner的伪元素:before和:after来实现

上下的边框是从中间往两边逐渐展开:scaleX(0)到scaleX(1)

左右的边框是从中间往上下两边展开:scaleY(0)到scaleY(1)

形成了一个四方形从中间向边角逐渐发光的效果:opacity:0到opacity:1。

其它就没什么技巧了。

scale介绍

scale(<number>[, <number>]):指定对象的2D scale(2D缩放)。第一个参数对应X轴,第二个参数对应Y轴。如果第二个参数未提供,则默认取第一个参数的值

scaleX(<number>):指定对象X轴的(水平方向)缩放

scaleY(<number>):指定对象Y轴的(垂直方向)缩放

读到这里,这篇“CSS3怎么实现逐渐发光的方格边框”文章已经介绍完毕,想要掌握这篇文章的知识点还需要大家自己动手实践使用过才能领会,如果想了解更多相关内容的文章,欢迎关注亿速云行业资讯频道。

亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI

开发者交流群×