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 trialjocelyn alsdorf
22,454 PointsI'd love to know more about sprites, why you used the pseudo-class, and how you knew where to position the icons...
I think the positioning choices where related to where the image was on the sprite sheet. Can someone give me a bit of insight into his choices for the icon CSS styling relating these issues? :)
5 Answers
Brian Hernandez
20,285 PointsYes, I'm pretty sure you are right with the background-position: X, Y; being the coordinates of where each image in the sprite sheet starts. Notice the sprite sheet used had the images stacked vertically so the X position was always 0 in the background-position: attribute. Only Y changed and it was -105 first then -210 as if moving down the sprite sheet. The width and height of each icon was previously defined in the .ft-icon::before pseudo class, so no matter where the image is set to start rendering from the sprite sheet, it will always be 164 w X 102 h. Something like Photoshop or Illustrator could easily be used to find out these starting coordinates to plug into the background-position.
I've always wondered why pseudo classes are used for this myself. I see it a lot in adding icons to buttons etc. I came across it enough to just accept that maybe it's best practice but never knew why as opposed to say dropping in a span tag in the div and using it instead...
larateles
Courses Plus Student 1,428 PointsHow I can use the Photoshop to see those coordinates to plug into the background-position and also find out measures and colours of other images/icons?
jocelyn alsdorf
22,454 PointsThanks guys! Appreciate you both taking the time to answer my question
rosinapissaco
13,401 PointsI also have the same question: Why is he using pseudo classes for icons here?
Carlos Mendoza
9,912 PointsI would also like some insight into why pseudo classes are being used. Thanks!
Courtney Mohr
1,096 PointsCourtney Mohr
1,096 PointsPersonally, I use sprites to reduce the amount of individual images that have to load throughout the page. Also, this means that once the page has loaded, using sprites, when it comes to roll overs, there's no "flash" while the page loads a separate image, but transitions seamlessly.
You also just have to play around a bit to see how many pixels to adjust the background-position.