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

General Discussion

Background texture

hi guys im looking for some help adding a background texture to my header. i dont seem to be getting anywhere despite using several examples from google.

my code is

header { width:1260px; margin: 0 auto; overflow:hidden; background-image: url('blackorchid.png') repeat-x; background-color: black; }

the png is in a folder named img and is 300px X 300px. even with /img infront of the png it doesnt work. can anybody spot what im doing wrong?

5 Answers

Hello, I made an example in Codepen . I hope it will help You. Also I believe that yours code don't work mainly because of not declaring height property and you should link to your image with 'img/blackorchid.png' .

hi thanks for the quick reply, even with the heightdeclared and img tag added, it will still not work. its really got be baffled!

Sorry I overlooked that in Your code earlier but if You want to use repeat You need to use shorthand background like this:

background: url('img/blackorchid.png') repeat-x;

or You have to write also background-repeat property:

background-image: url('img/blackorchid.png');
background-repeat: repeat-x;

If this won't work could You copy your code into codepen.io and share it to let me see it.

@Andrew -

Sounds like absolute vs relative paths issue.

You probably want:

background: url('../img/blackorchid.png') repeat-x;

Here's a quick primer on relative paths which should get you going.

If you are still confused, here's a good article on the difference between absolute and relative paths

hint: 90% of the time you'll want to use relative paths

spot on James, thanks a lot!