简体   繁体   English

CSS透明背景在IE7-8中不起作用

[英]CSS transparent background not working in IE7-8

I'm slowly deleting a few small png files I used for transparent divs, and replacing them with CSS code. 我正在慢慢删除一些用于透明div的小png文件,并用CSS代码替换它们。

This CSS code works on FF and IE9-10, and it helps in styling a textbox (it also changes the background when you click on it and adds a red 1px border): 此CSS代码可在FF和IE9-10上使用,并有助于设置文本框的样式(单击该文本框还会更改背景,并添加红色的1px边框):

#searchbars input {
    width: 130px;
    border: 1px solid #FFF;
    padding: 4px 2px 2px 10px;
    font-size: .9em;
    font-family: Helvetica, Arial, sans-serif;
    height: 16px;

    /* Fallback for web browsers that doesn't support RGBa */
    background: rgb(22, 22, 22) transparent; /* #161616 /
    /* RGBa with 0.28 opacity */
    background: rgba(22, 22, 22, 0.28);
    color: #FFF;
}

#searchbars input:active,
#searchbars input:focus {
    /* Fallback for web browsers that doesn't support RGBa */
    background: rgb(22, 22, 22) transparent; /* #161616 /
    /* RGBa with 0.75 opacity */
    background: rgba(22, 22, 22, 0.75); 
    border: 1px solid #ff8277;
}

Here's the conditional stylesheet for IE7: 这是IE7的条件样式表:

    /* For IE 5.5 - 7*/
    #searchbars input {
    filter:progid:DXImageTransform.Microsoft.gradient(startColorstr=#47161616, endColorstr=#47161616);
}

#searchbars input:active, #searchbars input:focus {
    filter:progid:DXImageTransform.Microsoft.gradient(startColorstr=#bf161616, endColorstr=#bf161616);
}

IE8 conditional sheet: IE8条件表:

    /* For IE 8*/
   #searchbars input {
    -ms-filter: "progid:DXImageTransform.Microsoft.gradient(startColorstr=#47161616, endColorstr=#47161616)";
}

#searchbars input:active, #searchbars input:focus {
    -ms-filter: "progid:DXImageTransform.Microsoft.gradient(startColorstr=#bf161616, endColorstr=#bf161616)";
}

I used IE10 developer tool, and tried to render the page using IE7-8-9 engines. 我使用IE10开发人员工具,并尝试使用IE7-8-9引擎呈现页面。

IE9/10/Firefox -> everything works as expected IE9 / 10 / Firefox->一切正常

IE8 -> Default background and the background change when you click on the textbox ( input:focus ) are not the ones expected. IE8->默认背景,当您单击文本框( input:focus )时,背景变化不是预期的。 It seems that opacity is not being applied even though the alpha hex values are correct. 即使alpha十六进制值正确,似乎也没有应用不透明度。

IE7 -> Default background works. IE7->默认后台工程。 Background change when you click on the textbox ( input:focus ) doesn't work. 当您单击文本框时,背景更改( input:focus )不起作用。 Also, the textbox border doesn't turn red when you click on it (see border: 1px solid #ff8277; property from the original sheet) 此外,单击文本框边框时,边框不会变为红色(请参见border: 1px solid #ff8277;原始工作表中的属性)

Here's a demo page: http://www.flapane.com/calcio.php 这是一个演示页面: http : //www.flapane.com/calcio.php

The search box is in the upper right corner, right of the social sharing buttons. 搜索框位于社交共享按钮的右上角。

Any hints? 有什么提示吗?

Thanks in advance 提前致谢

What's happening here is that the regular background declarations interfere with the filters . 这里发生的是常规的background声明会干扰filters

To fix it, add background: none to your inputs in LTE IE8 only, either through a second stylesheet or in the same document but by appending \\9 to the declaration. 要解决此问题,请添加background: none通过第二个样式表或在同一文档中,但在声明的末尾添加\\9 ,可以仅在LTE IE8中为您的inputs添加内容。

background: none\\9; targets IE8 and below, just like the wildcard hack ( *background: none; ) which targets IE7 and below, or the underscore hack ( _background: none; ) which targets IE6 and below. 以IE8及以下版本为目标,就像以IE7及以下版本为目标的通配符hack( *background: none; )或以IE6及以下版本为目标的下划线hack( _background: none; )一样。 You should however only need to use the first. 但是,您只需要使用第一个即可。

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

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