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 Basics (2014) Basic Selectors Intro to Selectors

Vanessa Elliott
Vanessa Elliott
1,742 Points

Patterns?

This question might be kind of petty but it's bugging me nonetheless. How in the world are selectors like patterns? That's just such an odd, confusing comparison to me.

2 Answers

Justin Horner
STAFF
Justin Horner
Treehouse Guest Teacher

Hello Vanessa,

I like the example Kevin Korte provided. I'd also like to add that I think the underlying comparison comes from how a selector actually works behind the scenes. Like a regular expression, a selector is a way for a developer/designer to say what they want to match and behind the scenes a pattern is used to find all the elements that match and apply the associated rules you've declared.

A pattern can simply be, "Please find every instance of this exact word" or as complex as, "Please find every instance of this string that ends with .PDF". In both cases, it's still a pattern but with different levels of complexity.

I hope this helps.

Vanessa Elliott
Vanessa Elliott
1,742 Points

That does help a lot! I can see how you could see a pattern in that, the pattern of "all cases of paragraph" or whatever. Thanks!

Kevin Korte
Kevin Korte
28,149 Points

It kinda is, I can see that. I think the comparison is suppose to mean that we can select elements that share similar attributes.

Let's say we had a pattern, Red/Green/Red/Green/Red/Green/Red/Green/Red/Green/Red/Green/Red/Green we could use selectors to pick all reds, or all greens, or every other red, or every 4th green, etc. And that selector rule itself kind of becomes a pattern.

Not a good example, I know. Maybe someone has a better one. But that's how my mind processed it.

Vanessa Elliott
Vanessa Elliott
1,742 Points

Well it's still a better example than I could have come up with lol, so thanks! It does help a bit.