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 Foundations Selectors Basic Attribute Selectors

If you have multiple forms and want to style them differently how would you target each form using attribute selectors?

On a site where you have multiple forms how would you target the individual forms using the attribute selectors to style them differently.

2 Answers

I think your best bet would be to add classes to them and style off of those but if that's not possible you can always try selecting on the action attribute:

form[action="/foo"] input {
    border: 2px solid red;
}

form[action="/bar"] input {
    border: 2px solid blue;
}
Jesus Mendoza
Jesus Mendoza
23,289 Points

Why would you want to do that if you can do it by adding different classes to each form and styling each class differently?