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

headlessui の Modal Dialog で画面が右にずれる

Posted at

tailwindcssを使っているとheadlessuiやtailwinduiなどのComponentテンプレートを使うと思う。Modalを表示した時に元の画面が裏でスクロールするのを防ぐため下記のCSSが<html>タグに付与される。

overflow: hidden; padding-right: 15px;

これは右側のスクロールバーが消えるため、そのレイアウト崩れをさせないために15pxのpaddingを取っているのだが、上部固定のheaderなどをposition: fixed; text-align: center;で設定していると(fixedはwindowに対しての絶対位置で指定するため)中央の位置が若干右にずれて、Modal表示時にカクッとなってしまう。

MaterialUIであればscrollLock={false}のような設定ができるが、そもそも背面のViewのスクロールをロックするというのはUX的には正しい挙動だと思うので、CSSで頑張る。

結論、tailwindcssを使っているなら、headerにpx-2(padding-left: 15px; padding-right: 15px;)を指定してやっておけば最初の位置からずれないので解決する。

1
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
1
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?