简体   繁体   English

图标的CSS背景颜色填充

[英]CSS Background color fill for the Icons

I am planning to use flag image for the status. 我打算将标志图像用作状态。 Please see the image 请看图片

在此处输入图片说明

In this image i want to fill the background color of the flag using CSS. 在此图像中,我想使用CSS填充标志的背景色。 The background color code is coming from server then i want to update the flag's color according to the color i got from server 背景颜色代码来自服务器,然后我想根据我从服务器获得的颜色来更新标志的颜色

I tried with SVG but it is not working in IE8. 我尝试使用SVG,但在IE8中不起作用。 Please help me how to do this. 请帮我怎么做。 thanks in advance for any help 预先感谢您的任何帮助

Note: I need to support From IE7 to latest browsers. 注意:我需要支持从IE7到最新的浏览器。 Don't want to use separate images for different colors. 不想为不同的颜色使用单独的图像。

You can use the Font Awesome Icon library to draw the flag as an font and change the color with css. 您可以使用Font Awesome Icon库将标记绘制为字体,并使用CSS更改颜色。

http://fortawesome.github.io/Font-Awesome/icons/ http://fortawesome.github.io/Font-Awesome/icons/

<i class="icon-flag" style="color: green"></i>
<i class="icon-flag" style="color: orange"></i>
<i class="icon-flag" style="color: red"></i>

example http://jsfiddle.net/QvQtg/1/ 示例http://jsfiddle.net/QvQtg/1/

If your flag will always be on the same background-color, you can simply use a .png, cut a hole where your color should appear and use background-color and background-image to create the desired result. 如果您的标志将始终使用相同的背景色,则只需使用.png,在应显示颜色的位置上切一个孔,然后使用background-color和background-image来创建所需的结果。

Html HTML

<div class="flag"></div>

CSS 的CSS

.flag {
    width: 45px;
    height: 54px;
    background-color: #f00;
    background-image: url(http://i.imgur.com/dD84kjR.png);
}

Example on JsFiddle: http://jsfiddle.net/a4EZ9/ JsFiddle上的示例: http : //jsfiddle.net/a4EZ9/

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

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