這篇文章給大家分享的是有關使用CSS實現漸變色動畫邊框效果的方法的內容。小編覺得挺實用的,因此分享給大家做個參考。一起跟隨小編過來看看吧。

https://github.com/comehope/front-end-daily-challenges/tree/master/016-colorful-gradient-animated-border
定義 dom,一個容器中包含一些文字:
<div class="box">
you are my<br>
FAVORITE
</div>居中顯示:
html,
body,
.box {
height: 100%;
display: flex;
align-items: center;
justify-content: center;
}設置頁面背景色:
body {
background: #222;
}設置容器和文字樣式:
.box {
color: white;
font-size: 2.5em;
width: 10em;
height: 5em;
background: #111;
font-family: sans-serif;
line-height: 1.5em;
text-align: center;
border-radius: 0.2em;
}用偽元素增加一個背板:
.box {
position: relative;
}
.box::after {
content: '';
position: absolute;
width: 102%;
height: 104%;
background-color: orange;
z-index: -1;
border-radius: 0.2em;
}把背板設置為漸變色的:
.box::after {
/*background-color: orange;*/
background-image: linear-gradient(60deg, aquamarine, cornflowerblue, goldenrod, hotpink, salmon, lightgreen, sandybrown, violet);
}為背板設置動畫效果:
.box::after {
background-size: 300%, 300%;
animation: animate_bg 5s ease infinite alternate;
}
@keyframes animate_bg {
0% {
background-position: 0%, 50%;
}
50% {
background-position: 100%, 50%;
}
100% {
background-position: 0%, 50%;
}
}最后,再為文字增加變色效果:
.box {
animation: animate_text 2s linear infinite alternate;
}
@keyframes animate_text {
from {
color: lime;
}
to {
color: yellow;
}
}大功告成!
感謝各位的閱讀!關于使用CSS實現漸變色動畫邊框效果的方法就分享到這里了,希望以上內容可以對大家有一定的幫助,讓大家可以學到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到吧!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。