1
I need a help!!
I’m making a form and each checkbox will have an image, however I did not want to manual by css each check, I wanted a script that already made automatic.
I know how to do this with the click() function, but I needed you to pull the page.
I would like to take the value of the Checkbox class and apply it as 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>
you want to identify the checkbox that is checked and assign a class to its label in the page load? that’s it?
– RBoschini
@Dirce I couldn’t understand what you want to do, by adding the attribute checked in the checkbox it already shows the icon.
– Leandro Angelo
So guys, I want each field to have an image. Actually ta gray, but I didn’t want to put a class for each one with the image, you know? Wanted to do td in Jquery
– Dirce
I edited the code below, now this taking the images in the page loading.
– RBoschini
managed to do? the solution worked?
– RBoschini