简体   繁体   中英

Add background image to font awesome icon

I'm wanting to add an image in a font awesome icon. Say I have the icon-star-empty and want to fill the internal part of that start with a photo. Is that possible? I have hacked at it, but gotten anywhere really. Any help would be appreciated.

[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/

Added a fiddle per request below.

The idea I had which only works in WebKit relies on -webkit-background-clip: text .

It also relies on there also being a solid version of the shape in question, in this case there is .icon-star to accompany .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;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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