javascript - custom checkbox with hidden input -
i making custom checkbox can have both own ui design, , still have input[type="checkbox"] in page purpose of toggling css classes , being able submit form , being taken form.
i aware if input has display: none; not passed form, hide since don't use visualy.
question: should take account when hidding it?
i'm thinking giving position: absolute; , negative margin not show up. label tag can still trigger it. should use opacity or visibility instead?
as can see, using opacity:0;, users still able click it. click near actual label on snippet below:
.chk { opacity:0; } .chk + label { background-color:red; height: 22px; width: 22px; display:inline-block; padding: 0 0 0 0px; cursor:pointer; } .chk:checked + label { background-color:blue; } <input type='checkbox' id='mychk' class='chk' /><label for='mychk' ></label> now, using negative margin make label disappear too:
.chk { margin:-100px; } .chk + label { background-color:red; height: 22px; width: 22px; display:inline-block; padding: 0 0 0 0px; cursor:pointer; } .chk:checked + label { background-color:blue; } <input type='checkbox' id='mychk' class='chk' /><label for='mychk' ></label> finally: visibility:hidden trick:
.chk { visibility:hidden; } .chk + label { background-color:red; height: 22px; width: 22px; display:inline-block; padding: 0 0 0 0px; cursor:pointer; } .chk:checked + label { background-color:blue; } <input type='checkbox' id='mychk' class='chk' /><label for='mychk' ></label> conclusion:
use visibility:hidden hide <input>. make invisible still inline display in page, without effecting label using it.
wiki
Comments
Post a Comment