2

I have 3 picture-checkboxes. With this code: Codepen 1 they looked like I want them.

In the next step I added the form: Codepen 2

Now you see - the form is creating 3 own checkboxes instead of using the picture. Can you help me please?

Saurav Rastogi
  • 9,575
  • 3
  • 29
  • 41
filledat
  • 47
  • 6
  • sorry for the codepen link, but i was not aloud to post pictures – filledat Dec 03 '16 at 05:21
  • Post a working code snippet here. – connexo Dec 03 '16 at 05:22
  • Your checkbox `id`s do not match your `label`s `for` attribute. Looks like you don't understand how image checkboxes work. You may want to **read** this: http://stackoverflow.com/questions/30663562/use-images-like-checkboxes/30663705#30663705 – connexo Dec 03 '16 at 05:25

1 Answers1

2

Change your <option>'s id to <label>'s for attribute (in your case use cb1, cb2 & cb3 in <option>'s id attribute), just like:

<li>
  <input type="checkbox" id="cb1" value="1" />
  <label for="cb1"><img src="http://betailor.de/wp-content/uploads/2016/12/engern.png" /></label>
</li>

Have a look at the working snippet below:

ul {
  list-style-type: none;
}

li {
  display: inline-block;
}

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

label {
  border: 1px solid #fff;
  padding: 10px;
  display: block;
  position: relative;
  margin: 10px;
  cursor: pointer;
}

label:before {
  background-color: white;
  color: white;
  content: " ";
  display: block;
  border-radius: 50%;
  border: 1px solid grey;
  position: absolute;
  top: -5px;
  left: -5px;
  width: 25px;
  height: 25px;
  text-align: center;
  line-height: 28px;
  transition-duration: 0.4s;
  transform: scale(0);
}

label img {
  height: 49px;
  width: 122px;
  transition-duration: 0.2s;
  transform-origin: 50% 50%;
}

:checked + label {
  border-color: #ddd;
}

:checked + label:before {
  content: "✓";
  background-color: green;
  transform: scale(1);
}

:checked + label img {
  transform: scale(0.9);
  box-shadow: 0 0 5px #333;
  z-index: -1;
}
<form method="post" action="processform.php">
<ul>
  <li><input type="checkbox" id="cb1" value="1" />
    <label for="cb1"><img src="http://betailor.de/wp-content/uploads/2016/12/engern.png" /></label>
  </li>
  <li><input type="checkbox" id="cb2" value="1" />
    <label for="cb2"><img src="http://betailor.de/wp-content/uploads/2016/12/Kürzen.png" /></label>
  </li>
  <li><input type="checkbox" id="cb3" value="1" />
    <label for="cb3"><img src="http://betailor.de/wp-content/uploads/2016/12/reapieren.png" /></label>
  </li>
</ul>
<input type="submit" name="send" value="Submit" />
</p>
</form>

Hope this helps!

Saurav Rastogi
  • 9,575
  • 3
  • 29
  • 41