Skip to content

Change the background image depending on the part of the image clicked

Notifications You must be signed in to change notification settings

yilverdeja/interactive-image-css

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CSS-Only Interactive Image

I wanted to create an interactive image using pure CSS - the idea was to have a different image depending on where the user clicked.

How it works

Using buttons and their active and focus states, we can set the image content to another path/url.

img {
  content: url("image.jpg")
}

button:active ~ img,
button:focus ~ img {
  content: url("new-image.jpg")
}

Preview (Codepen)

ezgif-3-7c7f7c0ab8

About

Change the background image depending on the part of the image clicked

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published