Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

CSS :has( :hover ) Selector

Im trying to get the following to work, but it doesn’t work with the :hover selector:

.a, .b {
  width: 100px;
  height: 100px;
  background: green;
  margin: 25px;
}

.a:has(+ .b:hover) {
  background: pink;
}
<div class="a"></div>
<div class="b"></div>

Without the :hover selector, it works in Chrome and on Firefox with the layout.css.has-selector.enabled flag enabled.

.a, .b {
  width: 100px;
  height: 100px;
  background: green;
  margin: 25px;
}

.a:has(+ .b) {
  background: pink;
}
<div class="a"></div>
<div class="b"></div>

Is there any other way to get this to work?
The original intent is to have two lines of a table connected, so when one has a mouse over, both lines get highlighted.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Thank you in advance for any help.

>Solution :

Here’s one that works for setting both .a and .b to pink on hover of either.

.a, .b {
  width: 100px;
  height: 100px;
  background: green;
  margin: 25px;
}

.a:hover,
.a:has(+ .b:hover)
{
  background: pink;
}

.b:hover,
.a:hover + .b
{
  background: pink;
}
<div class="a"></div>
<div class="b"></div>
<div class="a"></div>
<div class="b"></div>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading