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

stephanie harrison roberts
stephanie harrison roberts
1,713 Points

max width of site not working, anyone see why?!?

Hi all, cant seem to be able to get the max-width of this to work.....anyone know why? I'd like to try a max-width of 500px.

thanks

<!DOCTYPE html>
<html>
    <title>Coding Mama</title>
    <link rel="stylesheet" href="New.css">
    <body>


    </body>

</html>

```CSS
html
        {
          background: url(Brackets_Images/lights.jpg)no-repeat;
          height:100%;
          max-width: 500px;
          background-size: cover;
          background-position: 50% 50%;
          margin: 0 auto;

        }

3 Answers

John Lack-Wilson
John Lack-Wilson
8,181 Points

What is it that you are trying to achieve with this?

Max-width is used to limit how wide an element can go, i.e. the maximum allowable width, and it should really only be applied to elements within the body tag, not the html.

stephanie harrison roberts
stephanie harrison roberts
1,713 Points

really I'm just playing around trying to get familar with the way it all works. I'm trying to make the max width no larger than 500px no matter how big someones browser?

thanks

steph

John Lack-Wilson
John Lack-Wilson
8,181 Points

Ok, I see what you're trying to do.

The way to do this would be put a main tag inside the body and then set the max-width on the main element to 500px. It won't unfortunately work with the html or body tags (as far as I'm aware).

stephanie harrison roberts
stephanie harrison roberts
1,713 Points

Good stuff I'll try that. Its all a learning curve!!

thanks alot! :)

Steph