57
52

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 5 years have passed since last update.

iOSでbodyにoverflow: hiddenが効かないとき

Posted at

モーダルを出すとき、背景側の要素がスクロールしないようにしたい。
デスクトップ向けなら body 要素に対して overflow: hidden; を適用すれば済む。

しかしiOSだとこれだけではうまくいかない。
html 要素にも指定が必要である。

html {
  // autoで十分
  overflow: auto;
  height: 100%;
}

// モーダルを開いた時のbody
body.modal-open {
  overflow: hidden;
  height: 100%;
}

これでiOSでも、表示領域を固定できる。

57
52
2

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
57
52

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?