旋轉圖片在標準瀏覽器中靠 transform 就能解決,舊 IE 則要用它自家的 filter。
-moz-transform: rotate(-90deg); -webkit-transform: rotate(-90deg); transform: rotate(-90deg);
filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=3);
前面那一長串大小寫混雜的名稱不用理會,關鍵是後面的 rotation=3。這個參數只能填 0、1、2、3,沒有 4;填超出範圍的值圖片就不會旋轉了。
角度換算是把這些數字乘以 90 度,所以 rotation=3 代表順時針旋轉 270 度,等同 transform:rotate(270deg)。這也帶來一個限制:這種做法只能做 90、180、270 度的整數倍旋轉,無法指定任意角度。
若要在舊 IE 上實作任意角度,就得改用矩陣變換濾鏡(DXImageTransform.Microsoft.Matrix),計算量與可讀性都會差很多,通常不值得。
<style>
img {
margin: 100px auto 0;
-moz-transform: rotate(-90deg);
-webkit-transform: rotate(-90deg);
transform: rotate(-90deg);
filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=3);
}
</style>
<img src="images/006.gif" alt="" />
實務提醒:transform 屬性建議放在 filter 之後宣告,這樣支援 transform 的瀏覽器會採用標準屬性,而舊 IE 則自動落到 filter 上,兩邊各取所需、互不干擾。