Quick Tip: Mimic a Click Event with CSS
Tutorial Details
- Topic: CSS Click Events
- Difficulty: Moderate
- Estimated Completion Time:4 Minutes
- Post Graphic: Available on GraphicRiver
In today’s video quick tip, I’ll show you a nifty technique: we’ll use plain and simple CSS to mimic click events. The key is to use the helpful :target pseudo class.
Click the HD button for a clearer video.
Subscribe to our YouTube page to watch all of the video tutorials!
Final Source
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title></title>
<style>
figure { background: #e3e3e3; display: block; float: left;}
#zoom {
width: 200px;
-webkit-transition: width 1s;
-moz-transition: width 1s;
-o-transition: width 1s;
transition: width 1s;
}
/* Compliance = IE8+, Firefox 2+, Safari, Chrome, Opera 10+ */
#zoom:target {
width: 400px;
}
</style>
</head>
<body>
<h1> "Click" Effect with CSS </h1>
<figure>
<img id="zoom" src="http://d2o0t5hpnwv4c1.cloudfront.net/871_dryEE/dry-ee.png" alt="EE" />
<figcaption>
<ul>
<li>
<a href="#zoom">Zoom In</a>
</li>
<li>
<a href="#">Zoom Out</a>
</li>
</ul>
</figcaption>
</figure>
</body>
</html>
Conclusion
So what do you think? Pretty neat, huh? On a side note, within the comments, I’d like to know what your thoughts are on my usage of the figcaption element to house those “Zoom” links that are associated with the image. Do you think that’s a fair usage of the element? Thanks for watching!
Note: Want to add some source code? Type <pre><code> before it and </code></pre> after it. Find out more
- http://laroouse.com piyansitll
- Max
- nykeri
- http://www.alexanderwassberg.com Alexander
- http://zecel.com Shishant Todi
- JF
- JF
- http://khrrsn.com Keith
- http://khrrsn.com Keith
- http://www.stav.co Mathias M. Stav
- http://www.ShaneHudson.net Shane Hudson
- http://andrewdotson.com Andrew
- Mark Sinkinson
- http://www.amsheehan.com Alex
- Darren L.
- Matt
- Matt
- http://www.material-designer.com Chris
- Matt
- Mike Hopley
- http://randsco.com randsco
- Ethan
- http://www.willenewmedia.de/ WilleNewMedia
- WM
- http://www.macaronibros.com Fabio Fidanza
- http://www.material-designer.com Chris
- Callum
- http://twitter.com/DanielMorosan Danie
- http://www.linknomer.com andrei
- http://zaktus.net Zaktus
- Ricardo Nunes
- http://www.material-designer.com Chris
- Ricardo Nunes
- Joe
- http://willboling.com Will
- http://adrusi.com/ Adrian
- http://adventistsinglesdating.com chriss
- http://www.a.com Drake
- http://jeffri.net Jeffri Hong
- Abhijit
- Julien
- http://thimk.22web.net Thim
- http://www.cpusers.gr Texnologia
- http://www.stav.com Mathias M. Stav
- http://www.devseo.co.uk/ Alex Hall
- http://www.abijith.com Abijith
- http://idealthought.in Basanta
- http://codecanyon.net/user/Keliah Keliah
- http://www.jarodbillingslea.com/ Jarod Billingslea
- http://visualmushroom.daportfolio.com Hector abreu
- http://capitalh.ir/ CapitalH
- Sara
- Red_hawk
