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

HTML

Dylan Carter
Dylan Carter
4,780 Points

In CSS, using a selector with multiple elements on page...

okay so this isn't necessarily in the video but hypothetically...

lets say I have multiple paragraphs, using the p element of course, on a page, and I was to add styling to only one in particular. how would one go about doing this as I would imagine using p for the selector would apply it to all paragraphs on the page.

thanks!

2 Answers

samiff
samiff
31,206 Points

Hey Dylan, generally like Neil said, you could use class or id selectors, but you might also end up using CSS pseudo-classes like :nth-child() which would allow you to select a certain paragraph in numeric order. There are others and you'll learn about them in later videos.

Neil Anuskiewicz
Neil Anuskiewicz
11,007 Points

There are multiple ways depending on the scenario. Here are a couple ways:

Use class or id selectors instead of targeting the element itself. Target an element inside an element For example, the following would target only paragraphs that are in an article tag. article p { color: blue; }

I hope this helps.