Change element style on hover of another element

I have the following HTML code:
class="module-title"

Spantext Nonspantext

What I want to do is to hover over the h2 element and both of the spantext and nonspantext to change color. My limitation is that I cannot put the Nonspantext inside span tags (I cannot change the HTML code at all). The problem is that when I put the CSS rule .title :hover {color:#D01A13;} only the spantext changes color on hover and when I put the code .module-title :hover {color:#D01A13;} the nonspantext will change color if I hover over the spantext but I also want the opposite to happen. I am aware of the '+' and '~' rules in CSS but I could not make it work.

以上就是Change element style on hover of another element的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » JavaScript 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准

联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏