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
Chris Stauffer
Courses Plus Student 786 PointsTwo 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.)
James Barnett
39,199 PointsRemove 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
James Barnett
39,199 PointsIf 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
Ben Singer
8,621 PointsNice!
Chris Stauffer
Courses Plus Student 786 PointsThis was my fallback option! I was just curious if anyone more creative than me had another solution :) Thanks.
James Barnett
39,199 PointsI updated my pen to use half stars.
Tom Bedford
15,645 PointsCan't SVGs be transparent so you could still do the background fill? Or am I missing something..?
Chris Stauffer
Courses Plus Student 786 PointsChris Stauffer
Courses Plus Student 786 PointsFollow 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.