背景图像适合屏幕IE10

时间:2014-09-10 20:25:09

标签: css asp.net internet-explorer-10

我正在尝试在CSS中设置背景图像以适应屏幕。它适用于最新版本的Chrome,但是,我遇到了IE 10的问题。

html {
border-top: 10px solid #8A85A5;
background: url("http://www.lifeintempe.com/gfx/photos/2008-11-28-tempe-sunset-56632.jpg") no-repeat center center fixed ;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;

}

这就是它在IE 10中的显示方式。这里有很多空白区域...... 关于如何解决这个问题的任何建议?

enter image description here

我也尝试过添加......没有用。

min-height:100%;
min-width: 100%;

更新:

以上就是我在CSS文件中的全部内容。以下是我的html的样子:

<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Site.master.cs" Inherits="ScreenPop.Site" %>

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<link rel ="stylesheet" type ="text/css" href="Style/MyStyle.css" />
<asp:ContentPlaceHolder ID="head" runat="server">
</asp:ContentPlaceHolder>
</head>
<body>
    <form id="form1" runat="server">  
    <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server"></asp:ContentPlaceHolder>
    </form>
</body>
</html>

1 个答案:

答案 0 :(得分:1)

这对我有用:

html {
border-top: 10px solid #8A85A5;
background-color: #d5d5d5;
background-image: url('http://www.lifeintempe.com/gfx/photos/2008-11-28-tempe-sunset-56632.jpg');
background-repeat: no-repeat;
background-position: top center;
background-size: 100%;
filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='http://www.lifeintempe.com/gfx/photos/2008-11-28-tempe-sunset-56632.jpg', sizingMethod='scale');
-ms-filter: "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='http://www.lifeintempe.com/gfx/photos/2008-11-28-tempe-sunset-56632.jpg', sizingMethod='scale')";
}

解决方案2:

像这样使用wrapper div

<div id="bg">
  <img src="http://www.lifeintempe.com/gfx/photos/2008-11-28-tempe-sunset-56632.jpg" alt="">
</div>


#bg {
  position: fixed; 
  top: -50%; 
  left: -50%; 
  width: 200%; 
  height: 200%;
}
#bg img {
  position: absolute; 
  top: 0; 
  left: 0; 
  right: 0; 
  bottom: 0; 
  margin: auto; 
  min-width: 50%;
  min-height: 50%;
}

<强> DEMO

<强>更新

经过一段谷歌搜索后发现了这个,是的,它对我有用。我测试了它。希望它适合你。

<body> <img src="http://www.lifeintempe.com/gfx/photos/2008-11-28-tempe-sunset-56632.jpg" alt="background image" id="bg" />
<form id="form1" runat="server">
<div id="wrapper">
</div>
</form>
</body>


html, body {
height: 100%;
margin: 0;
padding: 0;
}
img#bg {
position:fixed;
top:0;
left:0;
width:100%;
height:100%;
}