Skip to content

Commit

Permalink
add 2025-01-16
Browse files Browse the repository at this point in the history
  • Loading branch information
BcRikko committed Jan 15, 2025
1 parent a61c1a9 commit ce1db03
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/pages/posts/2025-01-16/disable-scrolling-dialog.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
layout: ../../../layouts/Layout.astro
pubDate: "2025-01-16"
updatedDate: "2025-01-16"
title: "dialog要素の背面のスクロールを無効化する"
author: ダーシノ
description: "<dialog>要素(モーダルダイアログ)を表示するときに注意したいのが、元の要素のスクロール。 overscroll-behaviorで対処できなくはないが、カーソルが外れるとダイアログの裏側要素がスクロールされてしまう。"
tags: ["CSS"]
---

import Header from '../../../components/Header.astro'

<Header {...frontmatter} />

`<dialog>`要素(モーダルダイアログ)を表示するときに注意したいのが、元の要素のスクロール。
[overscroll-behavior](https://developer.mozilla.org/en-US/docs/Web/CSS/overscroll-behavior)で対処できなくはないが、カーソルが外れるとダイアログの裏側要素がスクロールされてしまう。

そんなときのTIPS。
```css
/* open状態のdiaog要素を持つ要素のスクロールを無効化する。 */
:has(dialog[open]) {
overflow: hidden;
}
```

0 comments on commit ce1db03

Please sign in to comment.