将背景图像添加到字体真棒图标

时间:2013-08-19 12:06:17

标签: css css3 font-awesome

我想在一个字体真棒图标中添加图片。假设我有一个星空图标,并希望用照片填充该开头的内部部分。那可能吗?我已经破解了它,但真的得到了。任何帮助将不胜感激。

[class^="icon-"]::before,
[class*=" icon-"]::before {
font-family: FontAwesome;
font-style: normal;
display: inline-block;
text-decoration: inherit;
}
.icon-star-empty:before {
content: "\f006";
}

.iconBackground:before {
font-size: 72px;
background: -webkit-gradient(linear, left top, left bottom, from(#f00), to(#333));
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
display initial;    
}    

http://jsfiddle.net/kZeSZ/3/

在下面的每个请求中添加了一个小提琴。

1 个答案:

答案 0 :(得分:1)

我只有在WebKit中工作的想法依赖于-webkit-background-clip: text

它还依赖于存在相关形状的可靠版本,在这种情况下.icon-star伴随着.icon-star-empty

http://jsfiddle.net/thirtydot/mPA8N/2/

.icon-star-empty-filled {
    font-size: 150px;
    position: relative;
}
.icon-star-empty-filled:before {
    content: "\f005";
    color: transparent;
    background: url(http://placekitten.com/300/300) no-repeat;
    background-size: cover;
    -webkit-background-clip: text;
}
.icon-star-empty-filled:after {
    content: "\f006";
    color: transparent;
    background: -webkit-gradient(linear, left top, left bottom, from(#f00), to(#333));
    -webkit-background-clip: text;
    position: absolute;
    top: 0;
    left: 0;
}