Alan Alan - 1 year ago 67
CSS Question

How to make a change in the dom that lasts for one click

I am building a webpage and i have set a body

. Is there a way to change the url of the image when the user presses the mouse key, and change it back when the mouse key is released? Basically the change lasts the same amount of time as the click itself.

Also, how do i make sure this change works for a click anywhere on the page? Will adding an event listener to the body element suffice? Thanks in advance.

Answer Source

Pure CSS:

body:active {
    background-image: [IMAGE];

Example jsfiddle

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download