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 Framework Basics Build a Website with Bootstrap Adding the Feature Icons

jocelyn alsdorf
jocelyn alsdorf
22,454 Points

I'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? :)

Courtney Mohr
Courtney Mohr
1,096 Points

Personally, 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.

5 Answers

Brian Hernandez
Brian Hernandez
20,285 Points

Yes, 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...

How 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
jocelyn alsdorf
22,454 Points

Thanks guys! Appreciate you both taking the time to answer my question

I also have the same question: Why is he using pseudo classes for icons here?

I would also like some insight into why pseudo classes are being used. Thanks!