Walkthrough: Viewport
Viewport - Walkthrough
Steps
- Style your
html
andbody
elements so they have a height of100%
. - Style your
body
so its background is black. - Set the
body
as a flex container and ensure any children are center aligned on both the horizontal and vertical axis. - Create a
main
tag inside your body with an id attribute ofviewport
. - Style the
main
element (using an ID CSS selector) so it has the following properties:- a width of
640px
- a height of
256px
- a
position
ofrelative
- an
overflow-x
ofauto
- a
background-image
which should be thewater0.png
image.
- a width of
Style your html
and body
elements so they have a height of 100%
.
In css/style.css
:
This will ensure our viewport is able to be centered vertically inside the browser window, as by default html
and body
are 100% wide but wrap their height to their contents. By specififying a height of 100%, these elements will now be as tall as the browser window.
Style your body
so its background is black. Set it as a flex container and ensure any children are center aligned on both the horizontal and vertical axis.
In css/style.css
:
justify-content
aligns the child elements horizontally, align-items
vertically.
Create a div
tag inside your body with an id attribute. Use viewport
as the id.
In between the opening and closing body
tags in index.html
:
Style the div
(using an ID CSS selector) so it has a width of 640px
, a height of 256px
, a position
of relative
, an overflow-x
of auto
, and finally a background image which should be the water0.png
image.
In css/style.css
:
We specify position: relative;
here because we want any items inside of the viewport to base their X/Y coordinates off of the top left of the viewport, not the browser window.
We specify overflow-x: auto;
because we want the viewport to scroll horizontally if any of it's children exceed the width.