Skip to content Skip to sidebar Skip to footer

How To Get Element Color Which Has No Background?

How to efficiently get color of element which has no background, but one of his parent has? For example this is 3 levels depth set: TOP1 is red TOP2 is green TOP3 doesn't have a

Solution 1:

There is no way to calculate the background of TOP3. If its background is not set, it is transparent. As such, it has the color of whatever is below it.

Example:

<divstyle="background: red; width: 100px; height: 100px">
  TOP1
  <divstyle="background: green; width: 80px; height: 80px">
    TOP2
    <divstyle="width: 60px; height: 100px; border: solid 1px yellow">
      TOP3
    </div></div></div>

Preview:

Here, TOP3 is half green, half white. No CSS value can tell you this.

Post a Comment for "How To Get Element Color Which Has No Background?"