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.

スマホのセーフエリア処理

Posted at

いつも調べて忘れるので書き残しておく。

viewportとenv()

大抵フッターエリアのボタンが押しにくいので、viewport-fit=coverを足し、env(safe-area-inset-bottom)をpaddingなどで足してあげればOK

hoge.html
<meta name='viewport' content='initial-scale=1, viewport-fit=cover'>
fuga.css
padding-top: env(safe-area-inset-top);
padding-right: env(safe-area-inset-right);
padding-bottom: env(safe-area-inset-bottom);
padding-left: env(safe-area-inset-left);

Javascriptでセーフエリアの値を取得する

CSSのカスタムプロパティを指定すると、JSからも取得しやすい

foo.css
:root {
    --safeareainsetbottom: env(safe-area-inset-bottom);
}
bar.js
getComputedStyle(document.documentElement).getPropertyValue('--safeareainsetbottom')

参考
https://benfrain.com/how-to-get-the-value-of-phone-notches-environment-variables-env-in-javascript-from-css/

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?