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"

Matthew Keys
Matthew Keys
1,922 Points

How to add multiple substring attribute selectors

Hi. I was wondering if it is possible to you are able to add multiple of these statements together, like for example if you were to do it with classes, you would go

.btn + .btn {
   color: green;
}

Is it possible to do something like that but for these? Like this:

a[href*="downloads"] + a[href*="downloads"] {
    margin: 20px;
}

1 Answer

james south
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
james south
Front End Web Development Techdegree Graduate 33,271 Points

the plus in css is not for 'chaining', it has a specific function, which is to select elements that immediately follow the former specified element, so div + p matches any p that immediately follows a div. it is called the adjacent sibling selector. if you want a rule to apply to multiple elements in css, you can just separate them with commas, like .class1, .class2, img, #grape { css declarations here }.

Matthew Keys
Matthew Keys
1,922 Points

I didn't mean it for chaining, I meant it for the adjacent sibling. How would I use the adjacent sibling selector with the example that i used above?