2013-08-19 149 views
0

我想添加图像的字体真棒图标。假设我有一个空的图标,并希望用照片填充该开始的内部部分。那可能吗?我已经黑了,但真的得到了任何地方。任何帮助,将不胜感激。添加背景图像到字体真棒图标

[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

你应该更详细一点的情况下,指定什么你试过等等。顺便说一句,你是否试图在'i'元素中强制使用'background-image'?试着让一个jsFiddle让我们随时随地玩你的想法。 –

+0

您对WebKit唯一解决方案感兴趣吗? – thirtydot

+0

@GuilhermeOderdenge不,我没有想到这一点。我会给它一个镜头。 – tattooedgeek

回答

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; 
} 
+0

你是一个天才! – tattooedgeek

+1

不客气。如果您需要支持其他浏览器,请使用SVG来完成此操作。 – thirtydot