IE8適配總結(一)
阿新 • • 發佈:2019-01-28
前端的適配主要包括各個瀏覽器和不同版本之間的適配,重點考慮IE8,所以這裡總結幾個目前知道的IE8適配方面的知識。
HTML5新標籤
很多HTML5新增的標籤在IE8中都不支援,比如header、section、footer等。
例如下面在html檔案中簡單的使用上面提到的這幾個標籤,看下在IE8和其他版本中的效果。
html程式碼:
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
header{
background: yellow;
width: 100px;
height: 50px;
}
section{
background: red;
width: 100px;
height: 100px;
}
footer{
width: 100px;
height: 50px;
background : aquamarine;
}
</style>
</head>
<body>
<header>
this is header
</header>
<section>
this is section
</section>
<footer>
this is footer
</footer>
</body>
</html>
在IE9中的效果如下:
在IE8中的效果如下:
可以看到這幾個標籤在IE8中並沒有效果,因為IE8對它們不提供支援。
flex佈局
flex和之前Android用到的佈局方式很相似,所以理解起來很簡單,但因為很多不支援,所以 就很少使用了。還是通過程式碼來看下在IE8下的效果。
html程式碼:
<div style="display: flex;justify-content: center;align-items: center;width: 200px;height: 200px;background: red">
<div style="width: 50px;height: 50px;background: aquamarine">1</div>
<div style="width: 50px;height: 50px;background: yellow">2</div>
<div style="width: 50px;height: 50px;background: mediumvioletred">3</div>
</div>
在IE10和IE8中的的效果分別如下:
可以看出flex佈局在IE8 甚至IE9中都不支援的。
rgba
rgba(255,255,255,0.5)這樣的半透明設定在IE8中也是不生效的。
CSS3新特性
如 border-radius這種設定圓角非常方便的也不支援
@media媒體查詢
IE8完全不支援媒體查詢,但可以通過respond.js檔案使其支援。具體使用方式:
<!--[if lt IE 9]>
<script src="https://cdn.bootcss.com/respond.js/1.4.2/respond.js"></script>
<![endif]-->
為IE8單獨設定CSS檔案
為IE8單獨編寫CSS檔案然後引入 :
<!--[if lt IE 8]><link rel="stylesheet" href="../css/indexforie.css"/><![endif]-->