mardi 20 janvier 2015

Style html checkboxes without IDs and labels

So I am using HTML checkboxes to create collapsible comment trees. The HTML and CSS code is fairly simple.


HTML:



<input type="checkbox" class="hide-box">
<div class="hidable">
Example<br>
<input type="checkbox" class="hide-box">
<div class="hidable">
Example


CSS:



.hide-box:checked~.hidable { display:none; }


My issue comes when I try to use a stylized checkbox. Every method I find to stylize a checkbox with CSS requires each checkbox to have a unique id which is matched to a "for=" in the checkbox label.


I'm going to be adding hundreds of these to several html documents with a mass find and replace, so I don't want to have to set up some kind of script to give each one a unique name.


Is there any method of stylizing the checkboxes that does not require giving each one a unique id? Preferably the solution would not require an javascript or jquery, I want to stick to html and css.





Aucun commentaire:

Enregistrer un commentaire