JSFiddle - React, Tailwind, and code Playground

by Deepak Sharma

HTML

<ul>
  <li><input type="checkbox" id="cb1" />
    <label for="cb1"><img src="https://dummyimage.com/120/000000/ffffff" /></label>
  </li>
  <li><input type="checkbox" id="cb2" />
    <label for="cb2"><img src="https://dummyimage.com/120/000000/ffffff" /></label>
  </li>
</ul>

CSS

ul {
  list-style-type: none;
}

li {
  display: inline-block;
}

input[type="checkbox"][id^="cb"] {
  display: none;
}

label {
  display: block;
  position: relative;
  cursor: pointer;
  width: 100%;
  height: 100%;
}

label:before {
  background-color: red;
  color: white;
  display: block;
  border: 1px solid red;
  position: absolute;
  width: 20px;
  height: 20px;
  text-align: center;
  line-height: 20px;
  transition-duration: 0.4s;
}

label img {
  height: 100%;
  width: 100%;
  border: 1px solid transparent;
}

:checked + label {
  border-color: red;
}

:checked + label:before {
  content: "✓";
  background-color: red;
  outline: 1px solid red;
  z-index: 99;
}

:checked + label img {
  z-index: -1;
  border: 1px solid red;
}