0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【MEMO】height: calc(100vh - 8px)がはみ出る話

Last updated at Posted at 2023-02-06

height: calc(100vh - 8px)がはみ出る話

検索窓を「bottom: 0」で表示しても出ないとき。
PCだと問題ない。が、スマホだと下にはみ出てしまう模様。
ナビゲーションバーとかの高さも「vh」に含まれるらしい。

「-webkit-fill-available」が計算で使えないようで、
なんか苦労したのでメモメモ。

CSS:


/* 親 */
.parent {
  /* 3. dvhが対応されていない場合用 (諦め) */
  height: calc(100vh - 8px);
  /* 2. varが対応されていない場合用 */
  height: calc(100dvh - 8px);
  /* 1. 変数を使う(要: JavaScript) */
  height: calc(var(--vh, 1vh) * 100 - 8px);
}

JavaScript:


// innerHeightの1%を変数に入れる
const vh = window.innerHeight * 0.01;
document.documentElement.style.setProperty('--vh', `${vh}px`);

iOS 14.2 Safariだと1で、Android 12 Chromeだと2で解決した。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?