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

Nestor Segura
Nestor Segura
13,025 Points

set the size of an img using css seudo class ::before and content:

I need to set the size of an image so that it fix to the size of the text that come with it, I am using this code:

***
<a href="#" id="twitter">Twitter</a> 

***
***

#twitter::before { content: url("icon/img/twitter.png")}

***

I get the image displayed, but I want to resize it to fix with the text.

have any one any idea?

1 Answer

width and height properties didn't work for me, but I found something useful on Stacoverflow. There are some good techniques to that. Just set the background of your link(for example) with that image, then remove it's repeat values and set its size and add some padding and voilla!

This is a snippet from my code:

a[href $= ".zip"] {
    background: url("img/zip.png");
}

a[href $= ".pdf"] {
    background: url("img/pdf.png");

}

a[href ^= "https://www.google"] {
    background-repeat: no-repeat;
    background-size: 16px 16px;
    padding: 0 0 0 25px;
}

http://stackoverflow.com/questions/6668577/using-before-css-pseudo-element-to-add-image-to-modal