DIV CSS 佈局教程網

讓 IE 支援 RGBa 背景色的方法
編輯:關於JavaScript     

先上程式碼:

<!DOCTYPE html>
<html>
<head>
<title>Demo</title>
<style type="text/css">
#div1 {
  padding: 10px;
  width: 380px;
  height: 205px;
  background: url(/upload/201007/20100713220102894.jpg);
}
#div2 {
  color: #FFF;
  font-size: 40px;
  font-weight: bold;
  text-align: center;
  height: 205px;
  line-height: 205px;
  background: rgba(125, 0, 0, .3);
  filter: progid:DXImageTransform.Microsoft.gradient(startColorstr=#4B7D0000, endColorstr=#4B7D0000);
}
</style>
</head>
<body>
Hello world!
</body>
</html>

DXImageTransform.Microsoft.gradient 濾鏡裡的 startColorstr 參數值是 #AARRGGBB 形式,其中 AA 代表不透明度的十六進位,00 表示完全透明,FF 就是全不透明,換算成十進位的範圍是 0~255,剩下的 RRGGBB 就是顏色的十六進位碼。

範例中 background: rgba(125, 0, 0, .3); 表示 30% 不透明度的紅色背景。如何把 30% 的不透明度轉換成十六進位?很簡單:先計算 #AA 的十進位 x,令 x/255 = 3/10,解得 x = 3×255/10,再把 x 換算成十六進位,約等於 4B。

下面附上範例中用到的圖片:

作者:周明智(文章部分內容來自 RGBa Browser Support)。

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