IE9+及其他瀏覽器實現背景圖片平鋪可能需要一個屬性就可以background-size:100%/cover;
但是ie8下background-size是不兼容的,因此我們需要用到濾鏡,來解決背景圖片拉伸問題。
僅需如下代碼:
filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(
src='../img/news/news-banner.png',
sizingMethod='scale');
-ms-filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(
src='../img/news/news-banner.png',
sizingMethod='scale');
eg:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no"> <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" /> <meta name="renderer" content="webkit" /> <title>投影儀-新聞中心</title> <style type="text/css"> *{margin: 0;padding: 0;} .news-banner{ width:100%; height:225px; background-position:50%; background-size:cover; background-repeat: no-repeat; background-image:url(news-banner.png); filter: progid:DXImageTransform.Microsoft.AlphaImageLoader( src='news-banner.png', sizingMethod='scale'); -ms-filter: progid:DXImageTransform.Microsoft.AlphaImageLoader( src='news-banner.png', sizingMethod='scale'); } </style> </head> <body> <div class="news-banner"> </div> </body> </html>
