DIV CSS 佈局教程網

您现在的位置: DIV+CSS佈局教程網 >> 網頁腳本 >  >> CSS入門知識 >> CSS進階教程
CSS 文字特效經典範例:立體、玻璃、內陰影與描邊
編輯:CSS進階教程     

這篇收錄的是一組很早期的 CSS 文字特效寫法,示範如何用多層文字疊加搭配濾鏡,做出立體、玻璃、內陰影與描邊等效果。以下範例Nowadays已不適用於現代瀏覽器,但它清楚說明了「以疊層模擬視覺層次」這個核心思路,理解之後用 text-shadow、-webkit-text-stroke 等標準屬性就能重現同樣的視覺。

3D Text(立體字)

做法是把同一段文字放兩層:底層套用模糊濾鏡,上層用亮色文字精準疊上去,營造出厚度。

Ttop.cn Ttop.cn

Glass Text(玻璃字)

兩層文字都套用 alpha 透明度,再搭配模糊,就能得到半透明的玻璃質感。

Ttop.cn Ttop.cn

Inner Shadow(內陰影)

先放一段白色文字,第二層用 mask 濾鏡上色、再疊陰影與 chroma 濾鏡,最後以相對定位 left:-200px 精準壓在第一層上方。

Ttop.cn Ttop.cn

Outline Text(描邊字)

由 mask、glow、chroma 三個濾鏡共同作用的結果。

Ttop.cn

與跑馬燈的結合

www.Ttop.cnwww.Ttop.cn

原始碼

<style type="text/css">
<!--
.sample {
  font-style: italic;
  font-family: arial black;
  font-size: 40px;
  font-weight: bold;
  cursor: hand;
}
-->
</style>

<h2>3D Text</h2>
<p>
 <span class="sample" style="width:200px; height:70; color:black;
     filter: Blur(Add=0, Direction=135, Strength=10);">Ttop.cn</span>
 <span class="sample" style="position:relative; left:-201; top:-15;
     width:200; color:#2984ff;">Ttop.cn</span>
</p>

<h2>Glass Text</h2>
<p>
 <span class="sample" style="width:200px; height:70; color:lightskyblue;
     filter: Alpha(Opacity=60) Blur(Add=0, Direction=135, Strength=20);">Ttop.cn</span>
 <span class="sample" style="position:relative; left:-201; top:-15;
     width:200; color:lightskyblue; filter: Alpha(Opacity=60);">Ttop.cn</span>
</p>

<h2>Inner Shadow</h2>
<p>
 <span class="sample" style="width:200px; height:70; color:white;">Ttop.cn</span>
 <span class="sample" style="width:200px; height:70; position:relative; left:-200;
     filter: mask(color=red) shadow(direction=135) chroma(color=red);">Ttop.cn</span>
</p>

<h2>Outline Text</h2>
<p><span class="sample" style="width:200px; height:70;
     filter: mask(color=red) glow(color=black, strength=1) chroma(color=red);">Ttop.cn</span></p>

<h2>與 Marquee 的結合</h2>
<p>
 <span class="sample" style="width:320px; height:70; color:black;
     filter: Blur(Add=0, Direction=135, Strength=10);">
  <marquee width="300" height="70" scrollamount="1" behavior="alternate" class="sample">www.Ttop.cn</marquee>
 </span>
 <span class="sample" style="position:relative; left:-320; top:-15; width:320; color:#2984ff;">
  <marquee width="320" height="70" scrollamount="1" behavior="alternate" class="sample">www.Ttop.cn</marquee>
 </span>
</p>

小提醒:Blur、Alpha、Mask、Glow、Chroma 都是舊版 IE 專屬的 filter,不屬於標準 CSS。今天要做同樣的效果,立體字用 text-shadow 多層疊加、描邊字用 -webkit-text-stroke、內陰影則可改用 inset box-shadow 搭配偽元素,都能獲得更好且跨瀏覽器的結果。

XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved