0
1

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】a:hoverが効かない時

Last updated at Posted at 2022-03-29

【問題】「画像はリンクホバーa:hoverが効くのにdivはきかない!?」

【解決回答】div要素に聞かせたいホバーはcssにdisplay: block;を追記。

いつもは画像素材を用いて、その素材をホバーで変色させることが多かったのですが、
以下のようなhtmlに:hoverでカーソルを乗せた時にdiv要素を少し透明にしようとしたら効かず。
scssファイルを考え直す。

元コード
.html
<div>
  <a href="/xxx/xxx">
    <div class="div-btn"><span>詳細はこちら</span></div>
  </a>
</div>
.scss
a:hover {
    opacity: 0.6;
}
解決コード

scssにdisplay: block;を追記

a:hover {
    opacity: 0.6;
+   display: block;
}

display: block;で親要素のサイズに合わせることができるらしい。



参考リンク

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?