我想在鼠标悬停在“ Article”标签上时更改背景颜色以更改类overlayLink的背景颜色

这是我的代码



.parent {
  width: 400px;
  height: 150px;
  position: relative;
  border: 1px solid #000;
}
.overlayLink {
  background-color: red;
  width: 100%;
  height: 100%;
  display: block;
}
.overlayLink:hover {
  color: #fff;
  background-color: #000;
}
article {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 50px;
  background-color: #efefef;
}

<div class="parent">
  <a href="#" class="overlayLink">a</a>
  <article>
    abcdefghijk
  </article>
</div>

最佳答案

你可以用这个



.parent {
  width: 400px;
  height: 150px;
  position: relative;
  border: 1px solid #000;
}
.overlayLink {
  background-color: red;
  width: 100%;
  height: 100%;
  display: block;
}
.parent:hover .overlayLink {
  color: #fff;
  background-color: #000;
}
article {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 50px;
  background-color: #efefef;
}

<div class="parent">
  <a href="#" class="overlayLink">a</a>
  <article>
    abcdefghijk
  </article>
</div>

关于html - 当鼠标悬停在html标签上时,我想在选择器之前更改背景颜色,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/47012855/

10-15 21:09