Blog IT

The most common way of creating a click event with CSS is using the checkbox hack. This method has broad browser support. You need to add a for attribute to the <label> element and an id attribute to the <input> element.

<!DOCTYPE html>
<html>
  <head>
    <style>
      label {
        display: block;
        background: #dbdbd9;
        width: 80px;
        height: 80px;
      }
      #box:checked + label {
        background: #fffc47;
        color: #666666;
      }
    </style>
  </head>
  <body>
    <form action="/form/submit" method="post">
      <input type="checkbox" id="box" />
      <label for="box">Click here</label>
    </form>
  </body>
</html>