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


Trying to put a background image next to my header instead of behind it.

Here is my code:

header a { display: block; background-image: url("../img/cupcakeart.jpg"); background-repeat: no-repeat; background-size: contain; background-position: left; margin: 0 0 0 10px; padding: 0 0 0 30x;

I thought the margin would push the header away from the image; but when I resize the browser, the header creeps right over the image.

The funny thing is I have this exact code elsewhere for other images and it works perfectly. I must be missing something. Please help. :-0

Daniel Houghton
Daniel Houghton
4,334 Points

have you tried using display: inline-block ?

2 Answers

Taylor Espejo
Taylor Espejo
3,939 Points

Hi Sheryl,

I believe Daniel is correct is saying that you need to set the image as both a block and inline element so that it does not occupy the entire region. In theory that would allow both to sit happily next to one another; however without seeing the rest of your code it is hard to diagnose. I would also suggest ensuring you havn't floated some of the elements that are in your header or applied any z-index, relative, absolute positioning etc that could be throwing off their happiness" to sit next to one another

Thank you both! Yes, inline-block fixed things.