CSS CSS Layout Basics Getting Started with CSS Layout Using a Mobile First Approach

ywang04
ywang04
6,732 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
MOD
Michael Hulet
Treehouse Moderator 46,564 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,732 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
Treehouse Moderator 46,564 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