-3

I have the below app structure. If I hover over e2 in either div, I would like e2 in both div1 and div2 to change their background color. Doing this with JS is somewhat trivial, but can this be done with pure CSS?

Scenario

cgsd
  • 1,242
  • 2
  • 13
  • 25
  • 1
    Please include your markup with the question, thanks – sol Sep 27 '17 at 14:44
  • 1
    Questions seeking code help must include the shortest code necessary to reproduce it **in the question itself** preferably in a [**Stack Snippet**](https://blog.stackoverflow.com/2014/09/introducing-runnable-javascript-css-and-html-code-snippets/). See [**How to create a Minimal, Complete, and Verifiable example**](http://stackoverflow.com/help/mcve) – Paulie_D Sep 27 '17 at 14:46
  • 2
    no, that can't be done with CSS alone - CSS selectors cannot address parent elements, and therefore also no siblings of parents or children of siblings of parents, which is the relatiion in your example. You have to stick to "trivial" JS... – Johannes Sep 27 '17 at 14:48
  • 3
    No...you can't affect elements that do not share a parent or are higher in the DOM with CSS. JS is a **requirement** here – Paulie_D Sep 27 '17 at 14:48
  • We need some codes and like some says... You need more than CSS. JS/Jquery is the simpliest way, but you can do it also in code behind (but don't think it's best way) – YannickIngenierie Sep 27 '17 at 14:56

1 Answers1

0

No, because hover property will not work on div that does not share a parent.

The similar has already been answered, here.

CSS properties cannot modify anything but elements and their children (they cannot access parents or siblings).

Anupam Raut
  • 268
  • 1
  • 2
  • 9