Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

CSS

Kenny Parewijck
Kenny Parewijck
4,602 Points

Question about an id="logo" with wraps an anker element wich wraps a header. Background color not possible. why?

Hello

i was trying some stuff and I hit a wall.. I was searching online for an explanation but without succes. here we go:

HTML:

  <a id="logo">
    <h1>Kenny Parewijck</h1>
    <h2>Ondernemer</h2>
  </a>

CSS:

#logo {

background-color: orange; border: 3px solid red;

}

( I have put the ' before the # in this post here because else way it doesn't show the # here in the post)

Problem:

The background-color does not change. I can see a strange thing with the border though.. (only border in at the start). Can someone help me and tell me why the background color doesn't turn orange?

Thanks!

2 Answers

Hi Kenny,

your problem lies with the "a" element, because it is an inline element and wrapping the "h1 / h2" which are block level elements its width is collapsing and a few other things are clearly going on that I don't have the technical answer for.

The simple answer is just add "display: block" to the logo and its good to go!

I have set up a quick pen to show you the difference just simply comment out display block in the css and you will see your original result.

PEN HERE

Hope this helps Craig

Kenny Parewijck
Kenny Parewijck
4,602 Points

Oke Craig,

Thanks for the answer! Very clear right now.