Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS next element (none sibling) selector [duplicate]

I have an HTML structure like this:

<svg>
   <path/>
</svg>
<img/>

Is there a way to do something like "display:block;" to the <img/> when <path/> is hovered, with CSS only?

like image 551
Dmitry Avatar asked Nov 02 '22 15:11

Dmitry


1 Answers

This is only possible if it is possible to select the parent of <path/> which unfortunately is not possible, so your answer is this is not possible.

If you would like to try this with javascript I can provide you a jQuery (not the best) example.

$('svg > path').hover(function(){
   $(this).parent().next().addClass('hover');
}, function() {
   $(this).parent().next().removeClass('hover');
});

Then in your css you can do.

img.hover{
   // These styles take effect when you hover `<path>`
}
like image 86
iConnor Avatar answered Nov 16 '22 08:11

iConnor