我想在鼠标悬停在html标签文章上时更改选择器之前的背景颜色

时间:2017-10-30 10:20:00

标签: html css

我希望在鼠标悬停在“文章”标签上时更改背景颜色以更改类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>

2 个答案:

答案 0 :(得分:3)

您可以使用此

&#13;
&#13;
.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;
}
&#13;
<div class="parent">
  <a href="#" class="overlayLink">a</a>
  <article>
    abcdefghijk
  </article>
</div>
&#13;
&#13;
&#13;

答案 1 :(得分:0)

可能会有所帮助。

&#13;
&#13;
.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;
}
&#13;
<div class="parent">
  <a href="#" class="overlayLink">a</a>
  <article>
    abcdefghijk
  </article>
</div>
&#13;
&#13;
&#13;

&#13;
&#13;
.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;
}
&#13;
<div class="parent">
  <a href="#" class="overlayLink">a</a>
  <article>
    abcdefghijk
  </article>
</div>
&#13;
&#13;
&#13;