24

The h-screen class which should set the height as the height of the screen doesn’t work on iOS. Is there a way to fix that ?

Pol
  • 1,132
  • 1
  • 11
  • 35
  • But what browser on iOS? What version of system, what device? Also it would be good idea to provide some fiddle to tests – chojnicki Apr 19 '20 at 17:26
  • @chojnicki I noticed it on my iPad Pro and iPhone both on safari with the latest iOS/iPadOS. But it appears to affect all mobile devices, check my answer :) – Pol Apr 20 '20 at 18:28

7 Answers7

31

Often i find useful to set a absolute wrapper outside the content with a .inset-0 class

<!-- this will use the whole viewport even in mobile -->
<div class="absolute inset-0">
    <div>
      lorem ipsum
    </div>
</div>
NEOJPK
  • 757
  • 1
  • 8
  • 17
  • 1
    This fixed my issue with `h-screen` where content was extending below the navigation bar in Samsung Internet on Android. Now it only fills the space visible above the navbar :) – mrossman Aug 17 '21 at 18:13
  • This worked just fine. Chrome, iOS! – Lucas L. Nov 30 '21 at 14:26
  • You are a lifesaver bro goodjob. – code.cycling Dec 10 '21 at 13:11
  • You have no idea how happy I am! All the other solutions I've seen involved confusing javascript and media queries. Thanks! – xornoz Nov 07 '22 at 06:44
  • 1
    This solution has some very weird side effects because it requires the dev to make the position of the element absolute. So no, this is not a very good solution I don't think, and I would avoid using it unless you know every potential side-effect that might occur by using it (in addition to every potential side-effect that might occur as code gets added and the apps scales up) As terrible as it sounds, you're probably going to avoid trouble in the long run by avoiding the use of absolutely positioned elements and instead setting the height using javascript instead of css. – John Miller Mar 29 '23 at 16:49
  • Hi @JohnMiller Absolute elements could have a relative child and it will negate all the sideeffects that you name. – NEOJPK Mar 31 '23 at 21:48
  • @NEOJPK No, it won't. Also, I think you mean relative parent, not relative child. – John Miller Apr 02 '23 at 18:08
  • here @JohnMiller learn something https://play.tailwindcss.com/umHIAf59aA pd: if im saying relative child its because i know what im talking about you dont get to correct me. Bye – NEOJPK Apr 03 '23 at 22:04
  • Either this doesn't work, or I am doing something wrong. What I did was basically wrap my content with the div shown. – Burak Kaymakci Aug 12 '23 at 13:16
16

Faced the same problem, and found out that we could use dvh (dynamic viewport height).

h-[calc(100dvh)] instead of h-screen.

However, it's better to add a fallback, just in case.

faheemkodi
  • 249
  • 3
  • 8
8

Run this JavaScript code on your app load

document.documentElement.style.setProperty("--vh", window.innerHeight * 0.01 + 'px');

and put this on your global styles to overwrite h-screen class

.h-screen {
    height: 100vh; /* Fallback for browsers that do not support Custom Properties */
    height: calc(var(--vh, 1vh) * 100);
}
6

The problem is that h-screen uses 100vh as the height. As it’s mentioned in this question, 100vh aims to not work on mobile devices.

But there is a way to tricks it, but it won’t be added to tailwind because it needs JS. To know more about this ‘trick’ check this article : The trick to viewport units on mobile

Pol
  • 1,132
  • 1
  • 11
  • 35
1

Adding h-[100svh] and h-screen as a fallback has solved my issue on iphones

0

Adding this to my css has proved to be a good solution:

@supports (-webkit-touch-callout: none) {
  .h-screen {
    height: -webkit-fill-available;
  }
}
Majolo
  • 56
  • 3
0

The main 'div' will take up the full height of the screen, while the inner 'div' will take up the available space, taking into account the height of the browser's navigation bar.

<div class="h-[100vh]">
    <div class="h-[100svh]">
      Bessie the cow
    </div>
</div>