From 8db32e8a3caaf682590d302c8453a9859ee63007 Mon Sep 17 00:00:00 2001 From: Carl Worth Date: Sat, 16 May 2020 15:06:50 -0700 Subject: [PATCH] Add some responsive layout for the page itself This is designed to use all the space available on a small device (such as a phone) but then to smoothly allow some distinctly-colored background to be visbile on a large device while maxing out the page width at a reasoable maximum width. This styling change does introduce a new containing "page" div around the content. --- index.html | 26 +++++++++++-------- style.css | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 91 insertions(+), 11 deletions(-) diff --git a/index.html b/index.html index 4da6188..bb9367f 100644 --- a/index.html +++ b/index.html @@ -10,19 +10,23 @@ -
+
-
- - -
+ -
- -
+
+ + +
- +
+ +
+ + + +
diff --git a/style.css b/style.css index 65b0b17..90ee7bd 100644 --- a/style.css +++ b/style.css @@ -19,6 +19,82 @@ h2 { font-weight: bold; } +/*\ +|*| +|*| Overall page layout +|*| +|*| Assumes: Top-level div with id="page" for all content +|*| +\*/ + +/* Mobile-first: At small sized we have a white background and use the + * entire screen width for the page (so the background color of the + * body is not visible anywhere). */ +body { + background-color: #333738; +} + +#page { + background-color: white; +} + +/* We never let the page content get larger than a large fixed width. + * + * And when the screen is wide enough, we can afford some "wasted" + * space on either side of the page content. This starts at 0 for a + * 620px wide page up to 50px on either side for a 720px wide page. + * + * Wider than that and we start to see the background on either side + * of the page content. + */ +#page { + box-sizing: border-box; + max-width: 720px; + margin-left: auto; + margin-right: auto; + padding-top: 0; + padding-bottom: 0; +} + +@media screen and (min-width: 620px) and (max-width: 720px) { + #page { + padding-left: calc((100% - 620px)/2); + padding-right: calc((100% - 620px)/2); + } +} + +@media screen and (min-width: 720px) { + #page { + padding-left: 50px; + padding-right: 50px; + } +} + +/* The calculations for height are different. We don't have any + * vertical centering, so instead we have only some fixed padding on + * the top. Then, the margin which allows the background to be visible + * on the top and bottom starts appearing at a viewport height of 648 + * and tops out at a size of 36px. + */ +#page { + min-height: 500px; + padding-top: 1em; +} + +@media screen and (min-height: 648px) and (max-height: 720px) { + #page { + margin-top: calc((100vh - 648px)/2); + margin-bottom: calc((100vh - 648px)/2); + } +} + +@media screen and (min-height: 720px) { + #page { + margin-top: 36px; + margin-bottom: 36px; + } +} + /*\ |*| |*| Responsive form layout -- 2.43.0