Advertisement
  1. Web Design
  2. HTML/CSS
  3. CSS

Quick Tip: Mimic a Click Event with CSS

Scroll to top
Read Time: 1 min

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.


Final Source

1
2
<!DOCTYPE html>
3
<html lang="en">
4
<head>
5
    <meta charset="UTF-8" />
6
    <title></title>
7
    <style>
8
       figure { background: #e3e3e3; display: block; float: left;}
9
       #zoom {
10
          width: 200px; 
11
          -webkit-transition: width 1s;
12
          -moz-transition: width 1s;
13
          -o-transition: width 1s;
14
          transition: width 1s;
15
      }
16
17
     /* Compliance = IE8+, Firefox 2+, Safari, Chrome, Opera 10+ */
18
      #zoom:target {
19
         width: 400px;
20
      }
21
    </style>
22
</head>
23
<body>
24
   <h1> "Click" Effect with CSS </h1>
25
   <figure>
26
      <img id="zoom" src="https://d2o0t5hpnwv4c1.cloudfront.net/871_dryEE/dry-ee.png" alt="EE" />
27
      <figcaption>
28
         <ul>
29
            <li>
30
               <a href="#zoom">Zoom In</a>
31
            </li>
32
            <li>
33
               <a href="#">Zoom Out</a>
34
            </li>
35
         </ul>
36
      </figcaption>
37
   </figure>
38
</body>
39
</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!

Advertisement
Did you find this post useful?
Want a weekly email summary?
Subscribe below and we’ll send you a weekly email summary of all new Web Design tutorials. Never miss out on learning about the next big thing.
Advertisement
Looking for something to help kick start your next project?
Envato Market has a range of items for sale to help get you started.