Check out a free preview of the full Build a Game Project: Feed-A-Star-Mole course

The "View Width & Height" Lesson is part of the full, Build a Game Project: Feed-A-Star-Mole course featured in this preview video. Here's what you'd learn in this lesson:

Brian explains why view width (vw) and view height (vh) are necessary to properly orient the game screen.

Preview
Close

Transcript from the "View Width & Height" Lesson

[00:00:00]
>> Brian Holt: The page here is actually only, that has a lot of vertical space that it could be taking up. And honestly, this is fine. We could leave it like this. But I'll show you kind of a little hack, that you can get it to take the whole height of a page.

[00:00:14]
You can do height, 100 vh.
>> Brian Holt: And now, it's vertically centered, as well. So, let's talk about what vh is. One, vh is only gonna work in really new browsers. So, if you're gonna use a vh, be careful, if you're trying to support older browsers. Right? But what it means is my browser is 100 vh tall.

[00:00:37]
And so, if I say, 100 vh, it says take 100% of what's available in the, this is called the viewport. So it's saying take 100% of the viewport. If I said something like 80 vh, it'd say, okay, take 80% of the available view height. So, now, if I refresh this, it's going to move up, just a tiny bit.

[00:01:01]
>> Brian Holt: So, again, what this is doing, it's saying the body should take 100% of the user's viewport. And then, here, I'm saying center it. That's why it ends up sitting directly in the middle of the viewport. Make sense? It's kind of a nice trick. You could here, as well, if you wanted to, do 100 vw,

[00:01:25]
>> Brian Holt: which does not stand for Volkswagen. It stands for 100% of the view width, as well. Right? And that would work, as well. But it already does that, so it's superfluous.
>> Brian Holt: Okay. So this is coming along already better. Right?

Learn Straight from the Experts Who Shape the Modern Web

  • In-depth Courses
  • Industry Leading Experts
  • Learning Paths
  • Live Interactive Workshops
Get Unlimited Access Now