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

Best Practice for creating page layout

Hi,

I've been wanting to create my own website with a layout which has a content area in the middle of the page with a background image or color behind it. This website is a good example of what I mean Link

I've managed to achieve this but I think the way am writing the code is considered bad practice, here's an example of what I did.

html {
    background: url('img/retro.jpg') repeat;
    max-width: 100%;
    }

body {
    font-family: 'Poly', serif;
    background: url('img/retro1.jpg') repeat;
    max-width: 92%;
    margin: 0 auto;
}

How should I properly write this ?

2 Answers

I wouldn't put styling on the html. Typically the only thing that I will add to the html tag is

html {height: 100%.}

As far as the body, I would also refrain from putting any max-width on it. Create another div inside the body and use that as your content box.

html:

<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
    <div>
       <p>Content goes here</p>
    </div>
</body>
</html>

css:

body {
    background: url('img/retro.jpg') repeat;
    font-family: 'Poly', serif;
}
div {
    background: url('img/retro1.jpg') repeat;
    max-width: 92%;
    margin: 0 auto;
}

Ok, I'll give this a go,

cheers for the reply