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 Selectors - Beyond the Basics Child, Adjacent, and General Sibling Combinators

Combinator for multiple children

Can we use combinators to target multiple children? For example under <h1>, we have children: <h2>, <label>, <h3>, <input>. User would like to target <h2> and <h3> under <h1>. Could we use 1 single line of code, instead of manually writing one code for each child like shown in below?

h1>h2 { font-size:2px; }

h1>h3 { font-size:2px; }

1 Answer

Steven Parker
Steven Parker
230,946 Points

Sure, you can have multiple selectors for the same rule, separated by commas:

h1>h2, h1>h3 { font-size:2px; }

I should point out that this element structure would not be good practice. A heading element should only contain phrasing content, which would not include other headings.