透過 IE 的 gradient 滤镜,可以為表格或單元格做出漂亮的漸變背景。以下是一個完整示例:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>表格漸變背景</title>
<style>
td{text-align:center;color:white;font-family:宋體;font-size:15px; font-weight:bold;border:2 dashed #FFFFFF;}
table{table-layout:fixed;border:2 dashed blue;width:567;height:234;filter:progid:DXImageTransform.Microsoft.gradient (startcolorstr=#990099,endcolorstr=#FFCCFF,gradientType=1);}
body{filter:progid:DXImageTransform.Microsoft.gradient(startcolorstr=#86CEFF,endcolorstr=#000099,gradientType=1);}
</style>
</head>
<body>
<center>
<table border="0" cellspacing="20" cellpadding="2">
<tr>
<td style="filter:progid:DXImageTransform.Microsoft.gradient(startcolorstr=#FF0000,endcolorstr=#FFCC66,gradientType=1)">
網頁陶吧-龍犢
</td>
<td style="filter:progid:DXImageTransform.Microsoft.gradient(startcolorstr=#006600,endcolorstr=#99FF99,gradientType=0)">
網頁陶吧
</td>
</tr>
</table>
<!-- gradientType=1 代表橫向漸變,gradientType=0 代表縱向漸變 -->
</center>
</body>
</html>
漸變效果的核心是:filter:progid:DXImageTransform.Microsoft.gradient(startcolorstr=起始色, endcolorstr=結束色, gradientType=方向)。其中 startcolorstr 為起始顏色、endcolorstr 為結束顏色,gradientType=1 表示橫向漸變、=0 表示縱向漸變。將這行滤镜分別套用到 table、td 或 body 上,即可呈現不同層次的漸變色彩。
需要說明的是,該 gradient 滤镜屬於 IE 私有特性;在現代標準瀏覽器中,建議改用 CSS3 的 linear-gradient 來實現相同且更相容的漸變效果。