Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

height 100% or 100vh on body & html? #70

Open
jensimmons opened this issue Dec 7, 2019 · 11 comments
Open

height 100% or 100vh on body & html? #70

jensimmons opened this issue Dec 7, 2019 · 11 comments

Comments

@jensimmons
Copy link
Owner

Do we want to include something like:

html, body {
  height: 100%;
}

or

html, body {
  min-height: 100vh;
}

???

to keep the page from being super short in the browser window.

@mirisuzanne
Copy link
Collaborator

I tend to use the latter (min-height) on every project. Doing it by hand I apply to either html or body - but as a default I see the sense in setting both.

@charakterziffer
Copy link

charakterziffer commented May 16, 2020

In this context maybe min-height: -webkit-fill-available; should be added. According to https://allthingssmitty.com/2020/05/11/css-fix-for-100vh-in-mobile-webkit/ it prevents the bottom of a website to be hidden behind mobile Safari’s menu bar.

@giuseppeg
Copy link

Probably it is not necessary to set it on the html element too

@Malvoz
Copy link
Contributor

Malvoz commented May 28, 2020

Cross-referencing w3c/csswg-drafts#4329 in regards to #70 (comment).

Edit:
Per https://twitter.com/bfgeek/status/1262459015155441664, to cater for Chromium aligning on Firefox's behaviour, add the declarations to both html and body:

html {
  height: -webkit-fill-available; /* https://twitter.com/bfgeek/status/1262465912025698304 */
}

html, body {
  min-height: 100%; /* We keep this right? */
  min-height: 100vh;
  min-height: -webkit-fill-available; /* We want the vendor-prefixed value to take affect
                                         in browsers that support it, fall back to 100vh,
                                         then 100%. */
}

@kripod
Copy link

kripod commented Jul 18, 2020

Cross-referencing w3c/csswg-drafts#4329 in regards to #70 (comment).

Edit:
Per https://twitter.com/bfgeek/status/1262459015155441664, to cater for Chromium aligning on Firefox's behaviour, add the declarations to both html and body:

html {
  height: -webkit-fill-available; /* https://twitter.com/bfgeek/status/1262465912025698304 */
}

html, body {
  min-height: 100%; /* We keep this right? */
  min-height: 100vh;
  min-height: -webkit-fill-available; /* We want the vendor-prefixed value to take affect
                                         in browsers that support it, fall back to 100vh,
                                         then 100%. */
}

I would love to see this approach implemented as a remedy. It seems to adapt content of any size, and would progressively enhance the user experience on mobile devices.

Sticky footers would be a breeze to implement with these additions.

@kripod
Copy link

kripod commented Jul 28, 2020

Now there is a PostCSS plugin written for the purpose, which avoids applying the fix in Chrome.

@jensimmons I hope you are on the path of recovery from COVID-19 and will get better soon. Take care of your health first, I wish you all the best!

@NMoore-STEM
Copy link

NMoore-STEM commented Oct 14, 2020

First comment on GH, but recently ran into issues of html and body having 0px height no matter what fix I used (including height:100%, height:auto, height:100vh, clear fixes, zeroed margin and padding, etc. etc.). I am relatively new to web dev.

I was looking for solutions online to my problem and found this conversation and wanted to share my troubleshooting approach as it seems to loosely apply to this scenario.

While inspecting elements, make note of the dimensions that show on hover as you move along the elements in your HTML (I am using FF dev tools included with the browser). The next element past the html and body that shows full height of the document is likely your problem, especially if it contains all other elements.

My page had a tiled svg pattern and many CSS rules applied to that element. Additionally, all other elements were children of this background div. The problematic rule that solved my problem was having position:absolute in there. Once that was removed, the html and body automatically took on the full height of all the other elements combined. I am assuming that the absolute positioning took everything out of the flow/ height calculations in the DOM? Anyhow, hope this helps others that may have the same issue.

This applies to the original issue as you might have container elements/divs as direct children of the body that have absolute positioning that is shortening your html or body height.

@BassOfBass
Copy link

Browsers tend not to agree on what constitutes a viewport value so using relative ones is safer bet.

@mirisuzanne
Copy link
Collaborator

The linked PostCSS plugin uses:

  1. browser-prefixes (-webkit-fill-available would be our first)
  2. browser-sniffing css hacks (-webkit-touch-callout is not relevant here except for the browsers excluded)

I'm a little bit wary of point 1 (it might need more discussion in the abstract), but I'm very wary about point 2.

On the other hand, that linked twitter thread includes a suggestion from Adam Argyle that doesn't rely on either of the above:

html {
  height: 100%;
}

body {
  min-height: 100%;
}

(He uses the block-size logical properties rather than height, which we could consider.)

@Flo2ent
Copy link

Flo2ent commented Jan 21, 2021

Hello, this is my proposal:

html {
  /* writing-mode: horizontal-tb ============================== */
  height: 100%;
  /* height: 100vh; -- Usefull? */
  height: -webkit-fill-available;


  /* writing-mode: vertical-rl ================================
                or vertical-lr ================================ */
  /* width: 100%; */
  /* width: 100vw;  -- Usefull? */
  /* width: -webkit-fill-available; */


  /* Logical properties ======================================= */
  block-size: -webkit-fill-available;
  /* stretch is the new value defined in Box Sizing 4: https://w3.org/TR/css-sizing-4/ */
  block-size: stretch;
}




body {
  /* writing-mode: horizontal-tb ============================== */
  min-height: 100%;
  min-height: -webkit-fill-available;


  /* writing-mode: vertical-rl ================================
                or vertical-lr ================================ */
  /* min-width: 100%; */
  /* min-width: -webkit-fill-available; */


  /* Logical properties ======================================= */
  min-block-size: -webkit-fill-available;
  min-block-size: stretch;
}

@Malvoz
Copy link
Contributor

Malvoz commented Jul 22, 2021

Not sure what the status of -webkit-fill-available is (or how the new lvh, svh, dvh, lvw, svw, and dvw units fit into this), but going back to the original question of:

html, body {
  height: 100%;
}

or

html, body {
  min-height: 100vh;
}

???

I think one important consideration between the two is that the former declaration allows authors to set e.g. <div> elements to height: 100% and have their expectations met. Refer to this SO post with, currently, 500k views: https://stackoverflow.com/questions/7049875/why-doesnt-height-100-work-to-expand-divs-to-the-screen-height.

kevduc referenced this issue in Theblackhole0614/password-manager Jul 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants