跨浏览器兼容图片不能铺满整个屏幕,background-size:cover不能兼容ie的问题。

2017-11-30 23:30:24 3,980 views

在body下面设置background设置背景时,发现背景不能全部覆盖屏幕,用background-size:cover及ie的滤镜效果都没法解决屏幕。
可以直接复制测试用例测试  ,   或者在当前链接下用ie测试 http://sandbox.runjs.cn/show/icueqkcc

<!DOCTYPE html>
<html lang="zh">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>Document</title>
    <style type="text/css">
      #container {
        z-index: -1;
        width: 100%;
        height: 100%;
        position: absolute;
        top: 0;
        background: url(https://ss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=1943249770,628140654&fm=200&gp=0.jpg) no-repeat;
      }
    </style>
  </head>
  <body>
    <img id="container" src="https://ss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=1943249770,628140654&fm=200&gp=0.jpg" />
    <div id="login">
      <div id="errorInfo"></div>
      <form action="" id="form">
        <label for="userName" style="margin-right: 10px;">用户名:</label><input type="text" name="" id="userName" style="width: 140px;height: 25px;" /> <br />
        <label for="secreate" style="margin-right: 10px;">密码:</label><input type="password" name="" id="secreate" style="width: 140px;height: 25px;" /><br />
        <button id="btn">登录</button>
        <a href="" id="forget" style="margin-left: 10px;">忘记密码?</a>
      </form>
    </div>
  </body>
</html>

 
通过设置  添加一个
<img id="container" src="https://ss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=1943249770,628140654&fm=200&gp=0.jpgimg/test.jpg" />
#container{
z-index: -1; width: 100%; height: 100%; position: absolute; top: 0; background: url(../img/test.jpg) no-repeat;
}
让图片覆盖整个屏幕;

0

分享到微信朋友圈

打开微信,点击底部的“发现”,
使用“扫一扫”即可将网页分享至朋友圈。