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

Better Syntax for vertical page with full-width backgrounds?

Hi, I'm working on a page that has many parts on one page, instead of individual pages. The background is full-width while the content is in a wrapper that is centered. I've seen this all over the web, and I have an idea how it's done... but it just seems like the syntax could be better than how I'm wanting to do it.

Basically, my understanding is that it is a div full the full width, with a div inside that (the wrapper), then with the main content inside... and you do this for every section.

Example: <div class="full-width"> <div class="wrapper"> <h2>This is top section</h2> </div> </div>

<div class="full-width">
    <div class="wrapper">
       <h2>This is middle section</h2>
    </div>
 </div> 

<div class="full-width">
    <div class="wrapper">
       <h2>This is bottom section</h2>
    </div>
 </div> 

is there a shorter, better way to do this? Additionally, is there a way to keep sections from being affected by margins of elements inside the wrapper tag? I have to purposely add padding or there will be a gap.

Thanks!

4 Answers

Can't you just set your container CSS class to whatever percentage or pixel width you want and then crack on as per?

I was thinking something like this: http://codepen.io/trickstur/pen/eidmA

But for some reason it seems like it's probably not the most optimal way to do it.

If you want the backgrounds to span across the whole page but limit the contents width sadly there really isn't a better way right now.

Ok, thanks Alexander Smith. That's what I was figuring.