简体   繁体   English

使用CSS设置样式的按钮元素在IE6中未显示背景图像

[英]Button element styled with CSS is not showing the background-image in IE6

I have a legacy web application that is targeted for IE 6 and is being reskinned. 我有一个针对IE 6的旧版Web应用程序,并且正在重新设置外观。 The buttons are having the default browser button look replaced with a blue button image. 这些按钮的默认浏览器按钮外观已替换为蓝色按钮图像。

IE8中的按钮IE6中的按钮

My following HTML and CSS works fine on IE 8, but not in IE 6. 我以下的HTML和CSS在IE 8上运行良好,但在IE 6上却无法正常运行。

HTML HTML

<button id="add">Add</button>

CSS CSS

button
{
    width: 110px;
    height: 28px;
    background-image: url('../images/button.png');
    background-color: transparent;
    border: 0px none #ff0000;
    cursor: hand;
    font-family: Myriad Pro, Helvetica;
    font-weight: bold;
    font-size: 12px;
    color: #ffffff;
}

Using CSS, how can I get the background image to show in IE 6? 使用CSS,如何使背景图片显示在IE 6中?

Ideally the fix could be put in an ie6.css to make it easy to remove when IE6 support is eventually dropped. 理想情况下,可以将修复程序放在ie6.css中,以便在最终放弃IE6支持时轻松删除该修复程序。


Please no comments about dropping support for IE6. 关于删除对IE6的支持,请不要发表任何评论。 This legacy application is designed only for IE6 and used internally at an organisation where IE6 is the ONLY supported browser. 此旧版应用程序仅适用于IE6,并在仅支持IE6的浏览器的组织内部使用。

If the recesses of my memory on IE6 serve me well, it does not recognize background-image on a button element. 如果我在IE6上的记忆凹处对我有好处,则它不能识别button元素上的background-image Nothing you can do about it. 您无能为力。

Although, again based on memory, if you can change it to an input (attribute type="image" ) you might be able to get the effect you want even on IE6. 尽管再次基于内存,但是如果您可以将其更改为input (属性type="image" ),即使在IE6上,您也可以得到想要的效果。

Using the background CSS property instead of the background-image property does the trick as described in this blog post (excerpt below). 使用background CSS属性而不是background-image属性可以完成此博客文章中所述的技巧(以下摘录)。

The background-image property that worked in Firefox 2.0 just did not have any effect on IE6. 在Firefox 2.0中起作用的background-image属性只是对IE6没有任何影响。 After a bit of googling, I realized that the background-image property will not work on IE and that we need to use the background property. 经过一番谷歌搜索后,我意识到background-image属性在IE上不起作用,我们需要使用background属性。

This is what works for me: 这对我有效:

button
{
    background: transparent url('../images/button.png') no-repeat top;
}

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

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