LoginSignup
56
52

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でも、表示領域を固定できる。

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