溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

CSS3怎么實現(xiàn)逐漸發(fā)光的方格邊框

發(fā)布時間:2023-01-04 09:21:47 來源:億速云 閱讀:102 作者:iii 欄目:開發(fā)技術

本文小編為大家詳細介紹“CSS3怎么實現(xiàn)逐漸發(fā)光的方格邊框”,內(nèi)容詳細,步驟清晰,細節(jié)處理妥當,希望這篇“CSS3怎么實現(xiàn)逐漸發(fā)光的方格邊框”文章能幫助大家解決疑惑,下面跟著小編的思路慢慢深入,一起來學習新知識吧。

效果圖如下:

CSS3怎么實現(xiàn)逐漸發(fā)光的方格邊框

HTML代碼:

<div class="light">
 <img src="http://tva2.sinaimg.cn/crop.0.0.180.180.180/6830a53bjw8f2qo4xzc2zj20500500t0.jpg"/>
 <div class="light-inner">
  <p>前端開發(fā)博客</p>
  <p>關注前端開發(fā)</p>
 </div>
</div>

CSS代碼:

.light{
 background: #fff;
 width: 180px;
 height: 180px;
 margin: 100px auto;
 position: relative;
 text-align: center;
 color: #333;
 transform:translate3d(0,0,0);

}
.light-inner{
 padding: 60px 30px 0;
 pointer-events: none;
 position: absolute;
 left: 0;
 top: 0;
 bottom: 0;
 right: 0;
 text-align: center;
 transition: background 0.35s;
 backface-visibility: hidden;
}
.light-inner:before, .light-inner:after{
 display: block;
 content: "";
 position: absolute;
 left: 30px;
 top: 30px;
 right: 30px;
 bottom: 30px;
 border: 1px solid #fff;
 opacity: 0;
 transition: opacity 0.35s, transform 0.35s;
}
.light-inner:before{
 border-left: 0;
 border-right: 0;
 transform:scaleX(0,1);
}
.light-inner:after{
 border-top: 0;
 border-bottom: 0;
 transform: scaleY(1,0);
}
.light:hover .light-inner{
 background: #458fd2
}
.light:hover .light-inner:before, .light:hover .light-inner:after{
 opacity: 1;
 transform: scale3d(1,1,1);
}

.light-inner p{
 transition: opacity .35s, transform 0.35s;
 transform: translate3d(0,20px,0);
 color: #fff;
 opacity: 0;
 line-height: 30px;
}
.light:hover .light-inner p{
 transform: translate3d(0,0,0);
 opacity: 1;
}

實現(xiàn)步驟:

發(fā)光的方格,主要是通過.light-inner的偽元素:before和:after來實現(xiàn)

上下的邊框是從中間往兩邊逐漸展開:scaleX(0)到scaleX(1)

左右的邊框是從中間往上下兩邊展開:scaleY(0)到scaleY(1)

形成了一個四方形從中間向邊角逐漸發(fā)光的效果:opacity:0到opacity:1。

其它就沒什么技巧了。

scale介紹

scale(<number>[, <number>]):指定對象的2D scale(2D縮放)。第一個參數(shù)對應X軸,第二個參數(shù)對應Y軸。如果第二個參數(shù)未提供,則默認取第一個參數(shù)的值

scaleX(<number>):指定對象X軸的(水平方向)縮放

scaleY(<number>):指定對象Y軸的(垂直方向)縮放

讀到這里,這篇“CSS3怎么實現(xiàn)逐漸發(fā)光的方格邊框”文章已經(jīng)介紹完畢,想要掌握這篇文章的知識點還需要大家自己動手實踐使用過才能領會,如果想了解更多相關內(nèi)容的文章,歡迎關注億速云行業(yè)資訊頻道。

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI