|
導讀網頁的本質就是超級文本標記語言,通過結合使用其他的Web技術(如:腳本語言、公共網關接口、組件等),可以創造出功能強大的網頁。因而,超級文本標記語言是萬維網(Web)編程的基礎,也就是說萬維網是建立... 網頁的本質就是超級文本標記語言,通過結合使用其他的Web技術(如:腳本語言、公共網關接口、組件等),可以創造出功能強大的網頁。因而,超級文本標記語言是萬維網(Web)編程的基礎,也就是說萬維網是建立在超文本基礎之上的。超級文本標記語言之所以稱為超文本標記語言,是因為文本中包含了所謂“超級鏈接”點。 本篇文章給大家帶來的內容是關于如何使用純CSS實現彩虹條紋文字的效果(附代碼),有一定的參考價值,有需要的朋友可以參考一下,希望對你有所幫助。效果預覽
源代碼下載https://github.com/comehope/front-end-daily-challenges 代碼解讀定義 dom,容器中包含文本,并且包含4個 <span> 用于特效,<span> 的 data-text 屬性值為與文本相同: <p class="rainbow">
web
<span data-text="web"></span>
<span data-text="web"></span>
<span data-text="web"></span>
<span data-text="web"></span>
</p>居中顯示: html, body {
height: 100%;
display: flex;
align-items: center;
justify-content: center;
background: black;
}定義文本樣式: .rainbow {
color: white;
font-size: 300px;
text-transform: uppercase;
font-family: sans-serif;
font-weight: bold;
line-height: 1em;
position: relative;
}用偽元素增加圖層,形成彩虹效果: .rainbow span::before,
.rainbow span::after {
content: attr(data-text);
position: absolute;
top: 0;
left: 0;
overflow: hidden;
}
.rainbow span:nth-child(1)::before {
color: orchid;
z-index: 1;
height: calc(100% - 10% * 1);
}
.rainbow span:nth-child(1)::after {
color: mediumpurple;
z-index: 2;
height: calc(100% - 10% * 2);
}
.rainbow span:nth-child(2)::before {
color: deepskyblue;
z-index: 3;
height: calc(100% - 10% * 3);
}
.rainbow span:nth-child(2)::after {
color: cyan;
z-index: 4;
height: calc(100% - 10% * 4);
}
.rainbow span:nth-child(3)::before {
color: mediumspringgreen;
z-index: 5;
height: calc(100% - 10% * 5);
}
.rainbow span:nth-child(3)::after {
color: yellow;
z-index: 6;
height: calc(100% - 10% * 6);
}
.rainbow span:nth-child(4)::before {
color: gold;
z-index: 7;
height: calc(100% - 10% * 7);
}
.rainbow span:nth-child(4)::after {
color: tomato;
z-index: 8;
height: calc(100% - 10% * 8);
}增加動畫效果: .rainbow span::before,
.rainbow span::after {
animation: animate 0.8s infinite alternate;
filter: opacity(0);
}
@keyframes animate {
from {
filter: opacity(0);
}
to {
filter: opacity(1);
}
}為圖層設置延時,增強動感: .rainbow span:nth-child(1)::before {
animation-delay: calc(0.8s - 0.1s * 1);
}
.rainbow span:nth-child(1)::after {
animation-delay: calc(0.8s - 0.1s * 2);
}
.rainbow span:nth-child(2)::before {
animation-delay: calc(0.8s - 0.1s * 3);
}
.rainbow span:nth-child(2)::after {
animation-delay: calc(0.8s - 0.1s * 4);
}
.rainbow span:nth-child(3)::before {
animation-delay: calc(0.8s - 0.1s * 5);
}
.rainbow span:nth-child(3)::after {
animation-delay: calc(0.8s - 0.1s * 6);
}
.rainbow span:nth-child(4)::before {
animation-delay: calc(0.8s - 0.1s * 7);
}
.rainbow span:nth-child(4)::after {
animation-delay: calc(0.8s - 0.1s * 8);
}最后,把原始文本設置為透明色: .rainbow {
color: transparent;
}大功告成! 相關推薦: 如何使用純CSS實現帶有金屬光澤的立體按鈕的動畫效果(附源碼)以上就是如何使用純CSS實現彩虹條紋文字的效果(附代碼)的詳細內容,更多請關注php中文網其它相關文章! 網站建設是一個廣義的術語,涵蓋了許多不同的技能和學科中所使用的生產和維護的網站。 |
溫馨提示:喜歡本站的話,請收藏一下本站!