Safari iOS 15 mobile: fixed element jumps when bottom bar disappears
Asked Answered
B

3

9

Say we have a fixed sidebar, this:

.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  min-width: 17em;
  height: 100%;
}

When the Safari bottom bar is visible it's ok, but when scrolling down it disappears and the sidebar remains for a while where it was and then jumps to fill the space below. It looks very buggy.

I tried to replace height with each one of the below solutions but none worked:

height: 100vh; // Sidebar is under the bottom bar

height: -webkit-fill-available; // Sidebar doesn't adjust its height

height: var(--window-inner-height); // CSS prop set via JS window.innerHeight. Same above

bottom: 0;

Any idea to solve?

Brettbretz answered 25/10, 2021 at 12:44 Comment(0)
S
0

You should use the environment variable safe-area-inset-bottom in your bottom margin or padding.

You can see an example in this video by Jen Simmons (see from 16:44 min)

Stoecker answered 25/8, 2022 at 9:46 Comment(1)
Adding a code sample would be helpful here :)Shool
G
0

Try dvh (dynamic viewport height).

.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  min-width: 17em;
  height: 100dvh;
}
Gideon answered 8/3, 2023 at 18:45 Comment(0)
C
0

This did the trick for me:

.pb-safe {
  padding-bottom: env(safe-area-inset-bottom);
}
Cestar answered 17/5, 2023 at 14:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.