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 CSS Selectors Going Further with Attribute Selectors and Pseudo-Classes Substring Matching Attribute Selectors - "Contains"

t y
t y
362 Points

Lets say I want to target the lake image and the trees image for a red border. Can I give the selector 2 values?

Like:

img[src*="lake, trees"] { border-color: red; }

3 Answers

I believe the only way to select different elements based on different attribute values is as follows:

img[src*="lake"], img[src*="trees"] { border-color: red; }

Hope that helps!

t y
t y
362 Points

Thanks for the reply, I will try it :)

ywang04
ywang04
6,762 Points

It works. Thanks a lot. :)

Thank you for the QUESTION and the ANSWER, I was wondering the same thing :))))

You could give both images the same class and the change the border color using CSS.Ex:

<img scr="lake" class="img">
<img src="trees" class="img">
.img {
border-color: solid red;
}
t y
t y
362 Points

Thanks for your advice, but this course was about styling elements without using id's / classes. So I was curious if you can do this without using a class.