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 1 year has passed since last update.

【CSS】子要素ホバー時に親要素にスタイルを適用する方法

Last updated at Posted at 2024-04-30

以下のように記述ると子要素ホバー時に親要素に対してスタイルを適用できます。

<div>
  <button>ボタン</button>
</div>

div {
  background: white; 
  height: 100vh;
  width: 100%;
  text-align:center;
}

button {
  margin:80px auto;
  display: inline-block;
  padding: 20px 40px 20px 40px;
  color: aliceblue;
  font-weight: bold;
  background: #333;
}

div:has(button:hover){
  background: #0000ff;
}

上記の場合にはbuttonにホバーするとdivbackgroundが青になります。

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?