【问题标题】:Background image fit on screen IE10背景图像适合屏幕 IE10
【发布时间】:2014-11-04 15:17: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 中的显示方式。有太多的空白...
关于如何解决此问题的任何建议?

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

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>

【问题讨论】:

  • 您是否尝试过在您的 css 中将 html 更改为 body
  • Chrome 只是在拉伸您的图像吗?无论哪种方式,您是否尝试过设置 width:100% ?
  • @imtherman,是的,我有。结果相同。
  • 你声明了什么doctype
  • jsfiddle.net/69evLca1/3 在 IE10 中为我工作。尝试设置height: 100%;width: 100%;。因为HTML 没有固有高度(它从视口继承)。

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


【解决方案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%;
}

【讨论】:

  • 它对我不起作用。这就是它的样子image
  • 您是否尝试将 CSS 提供给 body and html。像这样html,body{..CSShere}
  • 是的,我也试过了。它所做的一切都是在下面创建另一个像这样的栏:border-top: 10px solid #8A85A5;
  • 作为替代,您可以使用wrapper div 吗?对于您的所有内容。它将解决问题。如果你没问题,我可以更新答案。
  • 这很奇怪。上述两种解决方案都对我有用。这是一个随机猜测,但请尝试Clearing History and Cache of IE,然后尝试上述两种解决方案。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-02-28
  • 2013-11-24
  • 1970-01-01
  • 1970-01-01
  • 2022-01-21
  • 1970-01-01
  • 2018-01-11
相关资源
最近更新 更多