【问题标题】:How to convert RGBA to filter for older IE browsers如何将 RGBA 转换为旧 IE 浏览器的过滤器
【发布时间】:2014-03-20 21:11:09
【问题描述】:

我有以下 CSS 代码将背景设置为具有不透明度的颜色:

    #second-menu-navi a {
        float:left;
        width:125px;
        height:40px;
        line-height: 40px;
        vertical-align: middle;
        font-size:11px;
        color:#ffffff;
        text-decoration: none;
        background: rgb(1, 55, 97);
        background: rgba(1, 55, 97, .85); /*#013761; /*url('theImages/nav_menu_85_b.png') repeat; /*#013761;*/
        margin:0 3px 0 0 !important;
        /*background-image: none !important;*/
        padding:0 !important;

        -moz-border-radius-bottomleft: 4px; 
        -webkit-border-bottom-left-radius: 4px; 
        -khtml-border-bottom-left-radius: 4px; 
        border-bottom-left-radius: 4px;

        -moz-border-radius-bottomright: 4px; 
        -webkit-border-bottom-right-radius: 4px; 
        -khtml-border-bottom-right-radius: 4px; 
        border-bottom-right-radius: 4px;

        outline:none;

        filter:filter:progid:DXImageTransform.Microsoft.Alpha(opacity=85);
        /* For IE 8*/
        -ms-filter: "filter:progid:DXImageTransform.Microsoft.Alpha(opacity=85);";
    }
#tab-1:active, #tab-1:hover {
    background-color: #155E9B;
}
#tab-2:active, #tab-2:hover {
    background-color: #159B77;
}
#tab-3:active, #tab-3:hover {
    background-color: #1E9B15;
}
#tab-4:active, #tab-4:hover {
    background-color: #356101;
}
#tab-5:active, #tab-5:hover {
    background-color: #9B2B15;
}
#tab-6:active, #tab-6:hover {
    background-color: #9B1574;
}
#tab-7:active, #tab-7:hover {
    background-color: #70159B;
}
#break-line-2 {
    width:100%;
    height:7px;
    border-top:1px solid #02233C;
    background-color:#013761;
    position: fixed;
    top: 62px;
}

HTML:

<div id="second-menu-navi" class="navi">
            <a href="" id="tab-1">Why Choose Us</a>
            <a href="" id="tab-2">Physicians</a>
            <a href="" id="tab-3">Medical Specialties</a>
            <a href="" id="tab-4">Locations</a>
            <a href="" id="tab-5">Urgent Care</a>
            <a href="" id="tab-6">Radiology</a>
            <a href="" id="tab-7">Lab</a>
        </div>
</div>

它在 FF/Chrome/IE>=10 中运行良好。

如何编辑过滤器代码以确保它在不支持 rgba() 的 IE 中显示相同的内容?

【问题讨论】:

    标签: html css internet-explorer internet-explorer-8


    【解决方案1】:

    快速的谷歌搜索给了我这个网站,它有一个简单的转换器。输入您的 RGBA 代码,它会为您输出过滤器...

    http://kimili.com/journal/rgba-hsla-css-generator-for-internet-explorer/

    使用转换器:rgba(1, 55, 97, .85)

    变成这样……

    {
    background: transparent;
    -ms-filter: "progid:DXImageTransform.Microsoft.gradient(startColorstr=#D8013761,endColorstr=#D8013761)"; /* IE8 */
        filter: progid:DXImageTransform.Microsoft.gradient(startColorstr=#D8013761,endColorstr=#D8013761);   /* IE6 & 7 */
          zoom: 1;
    }
    

    【讨论】:

    • 现在遇到的唯一问题是,当悬停时使用纯色背景颜色时,它也使用相同的不透明度。当用户将鼠标悬停在每个菜单选项卡上时,我希望不透明度消失并显示纯色。
    • @SiKni8 - 我不确定我是否了解您在外观方面到底想要什么。您想要达到的预期效果是什么?如果您希望元素具有具有轻微不透明度的 BG 颜色,则在悬停时元素会恢复所有不透明度并再次变为实心,那么这应该像使用新的 :hover 选择器将所有不透明度更改为 1 一样简单。
    • 我在每次悬停时都使用了相同的代码,只是从#XXHEXVALUE 中删除了XX,悬停时会显示纯色。谢谢
    【解决方案2】:

    尝试将-ms-filter 行放在filter 之前,否则它不适用于IE8。有关它的一些信息,请参阅 this blog postthis CSSTricks comment

    【讨论】:

    • 有道理。谢谢。现在遇到的唯一问题是,当悬停时使用纯色背景颜色时,它也使用相同的不透明度。当用户将鼠标悬停在每个菜单选项卡上时,我希望不透明度消失并显示纯色。
    • 我能弄明白。为有帮助的回复点赞。
    • 我看到你在另一个答案的 cmets 中找到了那部分。干得好:-)
    猜你喜欢
    • 1970-01-01
    • 2020-08-06
    • 1970-01-01
    • 2016-08-10
    • 1970-01-01
    • 2010-10-27
    • 1970-01-01
    • 2017-02-12
    • 1970-01-01
    相关资源
    最近更新 更多