Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

CSS

Two color @font-face icon. Is it possible through pure CSS?

I've got an icon library built for a website. One of the icons is a star for product ratings. A 3.5 out of 5 rating would be: three orange stars, a half orange/half grey star and a grey star. Is it possible through CSS to tell the 50/50 icon to be two different colors?

(The icon appears different sizes on different parts of the website, so I want to keep it SVG. If it was the same size throughout, I would use a transparent row of stars with a percentage-based orange background fill.)

Follow up question! I've got the star ratings working just fine. I've placed one icon on top of the other to create a two color star. You can see that here: http://gtmsportswear.com/styleguide/#starReviews

However, if you change the font-size the negative left margin of the background star needs to change to match. I'm stumped as to how to do that without JavaScript.

Remove the negative margin from half-star:after and instead position the half stars relatively absolute.

.icons { position: relative; }
.half-star:before { position: absolute; }

2 Answers

If you have a half-star icon you should be able to do it.

This might give you some ideas on how to get started, you might try positioning a half-star icon on top of a full-star icon

http://codepen.io/jamesbarnett/pen/vlpkh

Nice!

This was my fallback option! I was just curious if anyone more creative than me had another solution :) Thanks.

I updated my pen to use half stars.

Can't SVGs be transparent so you could still do the background fill? Or am I missing something..?