https://github.com/comehope/front-end-daily-challenges/tree/master/016-colorful-gradient-animated-border
定義 dom,一個(gè)容器中包含一些文字:
<div class="box"> you are my<br> FAVORITE </div>
居中顯示:
html, body, .box { height: 100%; display: flex; align-items: center; justify-content: center; }
設(shè)置頁(yè)面背景色:
body { background: #222; }
設(shè)置容器和文字樣式:
.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; }
用偽元素增加一個(gè)背板:
.box { position: relative; } .box::after { content: ''; position: absolute; width: 102%; height: 104%; background-color: orange; z-index: -1; border-radius: 0.2em; }
把背板設(shè)置為漸變色的:
.box::after { /*background-color: orange;*/ background-image: linear-gradient(60deg, aquamarine, cornflowerblue, goldenrod, hotpink, salmon, lightgreen, sandybrown, violet); }
為背板設(shè)置動(dòng)畫效果:
.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; } }
大功告成!
聲明:本網(wǎng)頁(yè)內(nèi)容旨在傳播知識(shí),若有侵權(quán)等問題請(qǐng)及時(shí)與本網(wǎng)聯(lián)系,我們將在第一時(shí)間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com