css
多彩文字(Multi Colored Text)的製作的原理是,將二個文字相同而色彩不同的文字重合在一起,通過分別給元素加 clip 屬性,使上面和下面的文字被剪下位置不同,設定不同的色彩,從而產生多彩文字的效果,即Multi Colored Text。
clip 屬性:
clip : auto | rect ( number number number number )
參數:
auto:對象無剪下
rect ( number number number number ) :
依據上-右-下-左的順序提供自對象左上方為(0,0)座標計算的四個位移數值,其中任一數值都可用auto替換,即此邊不剪下
說明:
檢索或設定對象的可視地區。地區外的部分是透明的。
必須將position的值設為absolute,此屬性方可使用。
CSS代碼:
.textBottom {
color: #333333;
position: absolute;
left: 3em;
top: 1em;
font: 26px Century Gothic,Arial, Helvetica, sans-serif;
clip: rect(18px auto auto auto);
}
.textTop {
color: #CC0000;
position: absolute;
left: 3em;
top: 1em;
font: 26px Century Gothic,Arial, Helvetica, sans-serif;
clip: rect(0 auto 18px 0);
}
.container {
width: 28em;
height: 5em;
margin: 1em auto;
position: relative;
background: #F6F6F6;
}
XHTML代碼
<div class="container">
<a href="#" class="textTop">welcome to webjx.com</a>
<a href="#" class="textBottom">welcome to webjx.com</a>
</div>
查看運行效果:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>www.webjx.com</title><style type="text/css"><!-- body{ background: #FFFFFF; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 100%; line-height: 140%; text-align: center; padding: 0; margin: 0;}p{ margin: 0; text-aglin: center; }address{ font-size: 75%; }body,html{ height: 100%; }* html, * html body{ overflow: hidden;}#top{ min-height: 90%; overflow: auto; }* html #top{ height: 90%;}a{ text-decoration: none;}.textBottom { color: #333333; position: absolute; left: 3em; top: 1em; font: 26px "Century Gothic",Arial, Helvetica, sans-serif; clip: rect(18px auto auto auto);}.textTop { color: #CC0000; position: absolute; left: 3em; top: 1em; font: 26px "Century Gothic",Arial, Helvetica, sans-serif; clip: rect(0 auto 18px 0);}.container { width: 28em; height: 5em; margin: 1em auto; position: relative; background: #F6F6F6;}.textTop:hover { color: #808080;}.textBottom:hover { color: #FF4646;}--></style></head><body><div id="top"> <div class="container"> <a href="http://www.webjx.com/" class="textTop">welcome to webjx.com</a> </div> <p>文字的上半部分</p> <div class="container"> <a href="http://www.webjx.com/" class="textBottom">welcome to webjx.com</a> </div> <p>文字的下半部分</p> <div class="container"> <a href="http://www.webjx.com/" class="textTop">welcome to webjx.com</a> <a href="http://www.webjx.com/" class="textBottom">welcome to webjx.com</a> </div> <p>二組文字重合的效果</p></div></body></html>
[Ctrl+A 全部選擇 提示:你可先修改部分代碼,再按運行]