Change color on play button hover.

huangapple go评论64阅读模式
英文:

Change color on play button hover

问题

I have a play button with two shapes (triangle, and square) inside this parent div. When I hover over either of them, I want just the square to change color. Right now, it only changes color when hovered over the square and not the triangle that is laid on top of it. When hovered over the triangle, it goes back to its original color. Any ideas on how to target the triangle on hover to change the background color of just the square without using JS?

CODE:

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-css -->
.outer-square {
  height: 70px;
  width: 70px;
  background-color: #f2635d;
  border-radius: 6px;
  transition: 0.3s;
}

.outer-square:hover {
  background-color: #9c2514;
}

.triangle-play {
  position: absolute;
  width: 0;
  height: 0;
  border-style: solid;
  border-width: 17px 0 17px 30px;
  border-color: transparent transparent transparent #fff;
  z-index: 9;
  top: 17px;
  left: 23px;
}

<!-- language: lang-html -->
<a href="#">
  <div class="play-button" style="position: absolute; top: 34%; left: 23%;">
    <div class="triangle-play"></div>
    <div class="outer-square"></div>
  </div>
</a>

<!-- end snippet -->
英文:

I have a play button with two shapes (triangle, and square) inside this parent div. When I hover over either of them, I want just the square to change color. Right now, it only changes color when hovered over the square and not the triangle that is laid on top of it. When hovered over the triangle, it goes back to its original color Any ideas how to target the triangle on hover to change background color on just the square without using JS?

CODE

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-css -->

.outer-square {
  height: 70px;
  width: 70px;
  background-color: #f2635d;
  border-radius: 6px;
  transition: 0.3s;
}

.outer-square:hover {
  background-color: #9c2514;
}

.triangle-play {
  position: absolute;
  width: 0;
  height: 0;
  border-style: solid;
  border-width: 17px 0 17px 30px;
  border-color: transparent transparent transparent #fff;
  z-index: 9;
  top: 17px;
  left: 23px;
}

<!-- language: lang-html -->

&lt;a href=&quot;#&quot;&gt;
  &lt;div class=&quot;play-button&quot;style=&quot;position: absolute; top: 34%; left: 23%&quot;&gt;
    &lt;div class=&quot;triangle-play&quot;&gt;&lt;/div&gt;
    &lt;div class=&quot;outer-square&quot;&gt;&lt;/div&gt;
  &lt;/div&gt;
&lt;/a&gt;

<!-- end snippet -->

答案1

得分: 3

.outer-square:hover更改为.play-button:hover &gt; div.outer-square。这样,任何在父容器上悬停的操作都将改变外部正方形子元素的背景。

英文:

Change .outer-square:hover to .play-button:hover &gt; div.outer-square. This way, any hovering over the parent container will change the outer-square child's background.

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-css -->

.outer-square {
  height: 70px;
  width: 70px;
  background-color: #f2635d;
  border-radius: 6px;
  transition: 0.3s;
}

.play-button:hover &gt; div.outer-square {
  background-color: #9c2514;
}

.triangle-play {
  position: absolute;
  width: 0;
  height: 0;
  border-style: solid;
  border-width: 17px 0 17px 30px;
  border-color: transparent transparent transparent #fff;
  z-index: 9;
  top: 17px;
  left: 23px;
}

<!-- language: lang-html -->

&lt;a href=&quot;#&quot;&gt;
  &lt;div class=&quot;play-button&quot; style=&quot;position: absolute; top: 34%; left: 23%&quot;&gt;
    &lt;div class=&quot;triangle-play&quot;&gt;&lt;/div&gt;
    &lt;div class=&quot;outer-square&quot;&gt;&lt;/div&gt;
  &lt;/div&gt;
&lt;/a&gt;

<!-- end snippet -->

huangapple
  • 本文由 发表于 2023年5月18日 00:44:11
  • 转载请务必保留本文链接:https://go.coder-hub.com/76274394.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定