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

Sass variables when selecting attribute in CSS

Hello, I was wondering if such a thing may be done:

$logo-url : "../img/logo.png";

img[src=$logo-url] {
    vertical-align: middle;
}

In SASS you can create variables using the $ sign and then asign that variable where ever you want so yes the 1st can be done. As for the send you could do

    img[src="logo.png"]  { // Styles Here }

2 Answers

Steven Litton
Steven Litton
13,520 Points

I believe you need to always call an image src in the HTML file, you could use a background-image or content:url as an alternative to call it in the CSS but you would need to use a div instead of an img tag and it would have some compatibility issues.

If it has to be an img src then you could always use javascript variables instead.

Steven Litton
Steven Litton
13,520 Points

Ah sorry, I think I may have interpreted your question wrongly