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

【CSS】hover時のcssは有効のまま、クリックイベントのみを無効化する

Last updated at Posted at 2021-07-23

何をしたいか

  • hover時のcssは利用したいけど、クリックイベント自体は無効化したい。

今回、めったにないケースだとは思うのですが、あるボタンのhover時のcss(今回は背景色を変える実装)だけは有効にしたまま、ユーザーがクリックできないようにしたいという特殊な実装をすることになりました。

解決策

解決法は:activeの擬似クラスを使ってその中でpointer-events: none;するだけ。

.class-name {
  &:hover {
    background-color: blue;
  }
  &:active {
    pointer-events: none;
  }
}

これでhover時はちゃんと背景が青になるものの、クリックをしても何も起こらないという動作をさせることができました。

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?