62
55

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.

z-index の値を無視して背面要素を操作可能にするCSS

Last updated at Posted at 2015-09-11

装飾的な意味合いの要素を z-index を利用して前面に配置する際、ボタンなどの重要な要素が背面になりクリックなどの操作ができなくなってしまう場合があります。

z-index の重なり順を維持したまま背面要素の操作を可能にするには、前面要素に pointer-events: none; を指定します。

See the Pen qiita_83c48c7423ea0eb617b8 by Sho Uchida (@shouchida) on CodePen.

HTML

<div class="obj">(装飾的要素)</div>
<button type="button" class="btn">button</button>

CSS

.obj {
  position: absolute;
  z-index: 2;
  pointer-events: none;
}

.btn {
  position: absolute;
  z-index: 1;
}

pointer-events プロパティのブラウザサポート状況は以下となります。
主要ブラウザすべてで問題なく利用できます。

Can I use... | CSS pointer-events (for HTML)

62
55
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
62
55

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?