Trying to change the content of an image by clicking another image (image gallery viewer), using pure HTML/CSS.
I am using the gumby.css framework and currently have the following HTML:
<section id="sect">
<div class="three columns">
<img src"/images/help.png">
</div>
<div class="one column">
<img src"/images/help.png">
</div>
</section>
And the following css:
#sect .three.columns img:hover {
content:url("/images/about.png");
border: 5px solid red;
}
#sect .one.column img:active ~ #sect .three.columns img {
content:url("/images/about.png");
border: 5px solid red;
}
The first css rule for #sect .three.columns img:hover works perfectly, indicating I have selected the right element. But the second one #sect .one.column img:active ~ #sect .three.columns img does nothing upon active.
Refer to here for the meaning of ~.
Anyone have any ideas?
Thanks.
As noted in the comments, this isnt possible in the way you are currently implementing.
CSS rules depend on degrees of decendancy and cannot traverse the DOM, by say, ascending up one parent level, then moving across and back down (in layman terms). They are limited to only identifying siblings and children.
The
contentstyle is also only available to:beforeand:afterpseudo elements.As such, the alternative would be to apply the operation to the
activestate of the parent elements, removing the child images, and referencing thebackground-imageand notcontentproperty e.g.:Demo Fiddle
HTML
CSS