我想悬停一个元素来影响其他元素css

i would like hover one element to affect other elements css

本文关键字:元素 影响 其他 css 一个 悬停      更新时间:2023-09-26

在我的主框元素上添加了一个悬停状态,我想让它变成灰色,里面的文字变成白色

这是主元素:.blogcont

里面还有另外两个元素,分别是h4和另一个文本div:.listing

我想在。blogcont

上更改h4和其他div的字体颜色为白色。

希望这对你有帮助!

.blogcont {
  width: 300px;
  height: 300px;
  background: red;
  color: black
}
.blogcont:hover {
  background: grey;
}
.blogcont:hover h4,
.blogcont:hover .listing {
  color: white
}
<div class="blogcont">
  <h4>hellooo</h4>
  <div class="listing">listingggg</div>
</div>