I need a help !!
I'm making a form and every checkbox will have an image, however I did not want to do manual by css every check, I wanted a script that I already made automatic.
I can do this with the click () function, but I needed it to pull when I loaded the page.
I would like to take the value of the Checkbox class and apply it to the label background. But I wanted a function that works for everyone.
Can someone give me a light ?? Thanks
.estilos li{ float: left; list-style: none; width: 23%; margin-right: 2%;}
.estilos li:last-child{ margin-right: 0 }
input[type=checkbox] {
display:none;
cursor: pointer;
}
input[type=checkbox] + label
{
background: #ccc;
padding: 100px 0 10px;
width: 100%;
display:inline-block;
cursor: pointer;
text-align: right;
}
input[type=checkbox] + label img{
position: relative;
right: 20px;
opacity: 0;
}
input[type=checkbox]:checked + label
{
padding: 100px 0 10px;
width: 100%;
display:inline-block;
cursor: pointer;
-webkit-box-shadow: 0px 2px 13px 0px rgba(0,0,0,0.75);
-moz-box-shadow: 0px 2px 13px 0px rgba(0,0,0,0.75);
box-shadow: 0px 2px 13px 0px rgba(0,0,0,0.75);
}
input[type=checkbox]:checked + label img{
opacity: 1
}
<ul class="estilos">
<li>
<input type='checkbox' name='thing' value='Teste' id="thing" class="01" />
<label for="thing">
<img src="https://cdn0.iconfinder.com/data/icons/small-n-flat/24/678134-sign-check-128.png"width="36">
</label>
</li>
<li>
<input type='checkbox' name='thing' value='Teste' class="02" id="thing2" />
<label for="thing2">
<img src="https://cdn0.iconfinder.com/data/icons/small-n-flat/24/678134-sign-check-128.png"width="36">
</label>
</li>
<li>
<input type='checkbox' name='thing' value='Teste' class="01" id="thing3" />
<label for="thing3">
<img src="https://cdn0.iconfinder.com/data/icons/small-n-flat/24/678134-sign-check-128.png"width="36">
</label>
</li>
<li>
<input type='checkbox' name='thing' value='Teste' class="02" id="thing4" />
<label for="thing4">
<img src="https://cdn0.iconfinder.com/data/icons/small-n-flat/24/678134-sign-check-128.png"width="36">
</label>
</li>
<div class="clear"></div>
</ul>