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 CSS Layout Basics Getting Started with CSS Layout Using a Mobile First Approach

ywang04
ywang04
6,762 Points

The min-width value in media query

In this video, the min-width value is set as 769px. I right click the page and select inspect, the value on the top right corner becomes 769px after I zoom in the page. However, I noticed that the body's width is only shown as 754px. I am not sure why these two values are different. And how does chrome calculate the width as 769px?

Any comments are welcome. :)

1 Answer

Michael Hulet
Michael Hulet
47,911 Points

When you change the width/height of the window with Chrome's developer tools open, it shows you the viewport width and the viewport height in the format WIDTHxHEIGHT. If the body of your page is less than that, you can set it to be so by adding one of these blocks to your CSS:

html, body{
    height: 100%;
    width: 100%;
}
html, body{
    height: 1vh; /* vh is a unit that is relative to the viewport's height */
    width: 1vw; /* vw is a unit that is relative to the viewport's width */
}

The only real difference between the above snippets is that the second one uses a newer feature of CSS, so it won't be supported on many older browsers. If you care about support for older browsers, you should go with the first snippet

ywang04
ywang04
6,762 Points

Michael, thanks for your information. I am just wondering it is a default behaviour that the body width is less than viewport width without additional settings you mentioned.

Michael Hulet
Michael Hulet
47,911 Points

I believe it depends on the browser, but in my experience, the <html> and <body> are 0px high and wide by default, so these settings are necessary