简体   繁体   English

标签背景图片未显示在ie7上

[英]a tag background image not showing on ie7

I have some a tag that are assigned to class like: class='user-home' and I'm using this css to achieve background image: 我有一些分配给类的标签,例如: class='user-home' ,我正在使用此CSS来实现背景图片:

.user-options .user-home{
    background-image:url('../../img/user-home.png');
    background-position:center;
    background-size: 14px 14px;
    background-repeat:no-repeat;
    border: none;
}

And the problem- This is what I'm getting on chrome/mozila/ie11 问题-这就是我在chrome / mozila / ie11上遇到的问题

This is what I'm getting on ie7 这就是我要上的ie7

What will be the solution? 解决办法是什么? Thanks. 谢谢。

The rule background-size is not supported on ie7. ie7不支持规则background-size It is recommended to use small images (14X14) and not resize it with CSS rules, this way you're saving traffic and improving your page loading time. 建议使用小图像(14X14),不要使用CSS规则调整其大小,这样可以节省流量并缩短页面加载时间。

There is a workaround ( how-do-i-make-background-size-work-in-ie ) but I still think it's better to just resize your image. 有一种解决方法( 如何在背景中工作 ),但我仍然认为仅调整图像大小会更好。

That's because background-size is a CSS3 property which isn't supported before IE9... CSS background-size not working in IE7/8 这是因为background-size是CSS3属性,IE9之前不支持... CSS background-size在IE7 / 8中不起作用

Only solution i think is to edit image to 14px 14px 我认为唯一的解决方案是将图像编辑为14px 14px

The browsers like IE7 do not support CSS3 properties. IE7之类的浏览器不支持CSS3属性。 So you cannot use them otherwise you get these types of results. 因此,您不能使用它们,否则会得到这些类型的结果。

You need to change the background-image CSS to this: 您需要将背景图像CSS更改为此:

.user-options .user-home{
    background-image:url('../../img/user-home.png');
    background-position:center;
    background-repeat:no-repeat;
    border: none;
}

and now, edit the image resolutions and change its width and height to 14x14 yourself. 现在,编辑图像分辨率,并14x14将其宽度和高度更改为14x14

Or if you want to use the current CSS, please go to this website from Google: 或者,如果您想使用当前的CSS,请从Google转到此网站:

https://code.google.com/p/ie7-js/ https://code.google.com/p/ie7-js/

And from there, include the JS needed to make the IE behave like a standard browser, this is the code: 从那里,包括使IE像标准浏览器一样运行所需的JS,这是代码:

<!--[if lt IE 7]>
<script src="http://ie7-js.googlecode.com/svn/version/2.1(beta4)/IE7.js">
</script>
<![endif]-->

This JS will enable almost many of the CSS and HTML attributes. 该JS将启用几乎所有的CSS和HTML属性。 This should be included in head element. 这应该包含在head元素中。

Are you sure it's IE7 not the compatibility view (IE6) anyway background-size wont work with IE7 您确定它是IE7而不是兼容性视图(IE6),但背景大小无法与IE7一起使用

A way of your question, Earlier I used to use DD_belatedPNG Javascript to fix PNG issues in IE6 您提出问题的方式,之前我曾经使用DD_belatedPNG Javascript修复IE6中的PNG问题

you may use one of the following tools to fix all IE issues: 您可以使用以下工具之一来解决所有IE问题:

For other HTML5 fixes and Media Query I use excanvas.js and respond.js 对于其他HTML5修复和媒体查询我使用excanvas.jsrespond.js

Code could be as follows: 代码可能如下:

<!--[if lt IE 9]>
  <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
  <script src="https://oss.maxcdn.com/libs/respond.js/1.3.0/respond.min.js"></script>
<![endif]-->

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM