I have a site with a changing background image, on hover of certain elements. The image is usually dark, but sometimes light. The light images have the class .whiteImg
applied to them.
I have gotten this to work with just CSS, by having the 'background' images set as the sibling of the element that is hovered. For example:
HTML:
<ul>
<li>
<a>link 1</a>
<img src="http://foo.com/" />
</li>
<li>
<a>link 2</a>
<img src="http://foo.com/" />
</li>
<li>
<a>link 3</a>
<img src="http://foo.com/" class="whiteImg" />
</li>
</ul>
CSS:
img{
position: absolute;
top: 0; left: 0; bottom: 0; right: 0;
opacity: 0;
transition: opacity 1s;
}
li a:hover + img{
opacity: 1;
}
Now that all works fine. But I have body{color: #fff;}
by default but that needs to change to #000
when .whiteImg
is visible. I've tried solving this with jQuery (and it's color plugin) but the animation happens after the CSS animation. So I'm looking for a pure CSS solution to *make the body
color
change to black at the same time as .whiteImg
is shown.
Is there anyway to do this? I'm looking for something similar to
li a:hover + img.whiteImg < body {
color: #000;
}
which is inspired by the end of this post but obviously doesn't actually work.
Thanks.