将鼠标悬停在父

时间:2016-08-10 15:38:22

标签: css svg polygon fill

我有一个小难题,我正在努力解决..当你将鼠标悬停在父div上时,尝试同时获取多边形填充颜色和文本填充颜色。这可能通过CSS吗?希望避免使用javascript并使其与浏览器兼容。

Codepen示例:

http://codepen.io/okass/pen/OXAXkY

<svg viewBox="-1 -1 255 53"><a href="#">
<g id="cta-button">
  <polygon class="polygon-cta" points="252.72209 0 197.614579 51 0 51 0 0"></polygon>
  <text class="text-cta">
      <tspan x="22" y="34">Learn more</tspan>
  </text>
</g>
</a>

当您将鼠标悬停在#cta-button上时,我无法弄清楚如何将文本填充更改为白色...当您将鼠标悬停在文本上时,它会按预期工作,但当将鼠标悬停在多边形上时,文本会隐藏。< / p>

1 个答案:

答案 0 :(得分:5)

将文本颜色更改移至组悬停状态的触发器。

svg #cta-button:hover text{
  fill: #fff;
}

&#13;
&#13;
#cta-button {
  fill: transparent;
  stroke: #e9004b;
}
svg text {
  font-weight: bold;
  font-size: 26px;
  font-family: lato;
  fill: #E9004B;
  stroke: none;
}
#cta-button:hover {
  fill: #e9004b;
}
svg #cta-button:hover text {
  fill: #fff;
}
&#13;
<svg viewBox="-1 -1 255 53">
  <a href="#">
    <g id="cta-button">
      <polygon class="polygon-cta" points="252.72209 0 197.614579 51 0 51 0 0"></polygon>
      <text class="text-cta">
        <tspan x="22" y="34">Learn more</tspan>
      </text>
    </g>
  </a>
</svg>
&#13;
&#13;
&#13;