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 :only-child and :empty

I did a :empty and expect it to affect my <h1></h1>, but it did not. Any ideas why?

As the title goes: I did a :empty and expect it to affect my <h1></h1>, but it did not. Any ideas why?

As far as I know, h1 is a block level so it should display the bg color I added for :empty. Also did it in <span></span> and in <ul></ul> but it did just not affect the empty tags.

2 Answers

Shane Oliver
Shane Oliver
19,977 Points

If the tag is empty ie <h1></h1> it won't be shown unless it has a width or height set. Try something like this to test

H1 { width: 100px; height: 100px; }
H1:empty { background-color: #333; }
Jacob Bergdahl
Jacob Bergdahl
29,118 Points

It's hard to say without seeing the code :) Perhaps you had some whitespace between the tags?