CSS3 linear-gradient 普及前,IE 獨有 filter: progid:DXImageTransform.Microsoft.gradient 可實現漸變,但僅限 IE6~IE9,現代瀏覽器不支援。
<style>
table {
width: 567px; height: 234px;
border: 2px dashed blue;
filter: progid:DXImageTransform.Microsoft.gradient(
startColorstr=#990099, endColorstr=#FFCCFF, GradientType=1
);
}
td {
border: 2px dashed #fff; color: #fff; font: bold 15px "SimSun"; text-align: center;
}
td.grad-h { filter: progid:DXImageTransform.Microsoft.gradient(startColorstr=#FF0000, endColorstr=#FFCC66, GradientType=1); }
td.grad-v { filter: progid:DXImageTransform.Microsoft.gradient(startColorstr=#006600, endColorstr=#99FF99, GradientType=0); }
</style>
<table cellspacing="20" cellpadding="2">
<tr>
<td class="grad-h">橫向漸變</td>
<td class="grad-v">縱向漸變</td>
</tr>
</table>
GradientType=0:縱向(預設)。GradientType=1:橫向。startColorstr/endColorstr:ARGB 格式(含透明度)。.gradient-table {
background: linear-gradient(90deg, #990099, #ffccff); /* 橫向 */
/* 或 */
background: linear-gradient(180deg, #006600, #99ff99); /* 縱向 */
}
.gradient-cell-h { background: linear-gradient(90deg, #ff0000, #ffcc66); }
.gradient-cell-v { background: linear-gradient(180deg, #006600, #99ff99); }
請優先使用標準 linear-gradient,僅在必須支援舊 IE 時保留 filter 方案。