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 - "Begins With" and "Ends With"

Reid Wahl
Reid Wahl
2,989 Points

Combine "begins with" and "ends with" attribute selectors?

Is there a way to combine both of these selectors? For instance, to select external .jpg files? (e.g., [href^="http"] [href$=".jpg"])

1 Answer

Hi Reid,

Combining two attribute selectors is feasible.

a[href^="http"][href*="google"] {
    color: green;
 }
<html>
<head>
<style type="text/css">
 a[href^="http"][href*="google"] {
    color: green;
 }
</style>

</head>

<body>
<div class="hello-example">
    <a href="http://google.com">google</a><br>
    <a href="http://yahoo.com">yahoo</a><br>
</div>
</body>

</html>

Regards! Chunwei

Reid Wahl
Reid Wahl
2,989 Points

Thanks! I figured it was possible but didn't know what the syntax would be.

Reid Wahl
Reid Wahl
2,989 Points

(Maybe it's covered in a later video and I should've been more patient :P )