Imesh Chandrasiri
Imesh Chandrasiri

Reputation: 5699

Custom checkbox issue

I've developed a custom checkbox using a tutorial. The code is as following.

FIDDLE

Fiddel

HTML

<input type="checkbox" name="checkboxG1" id="checkboxG1" class="css-checkbox" />
<label for="checkboxG1" class="css-label"></label>

CSS

input[type=checkbox].css-checkbox {
    display:none;
}
input[type=checkbox].css-checkbox + label.css-label {
    padding-right: 20px;
    height: 14px;
    display: inline-block;
    line-height: 14px;
    background-repeat: no-repeat;
    background-position: 0px 0;
    font-size: 14px;
    vertical-align: middle;
    cursor: pointer;
}
input[type=checkbox].css-checkbox:checked + label.css-label {
    background-position: 0px -14px;
}
label.css-label {
    background-image:url(http://csscheckbox.com/checkboxes/u/csscheckbox_39e0df4737b77a2ca4a672a70ec70e86.png);
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -khtml-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

I'me trying to plug the above css to my existing application where the controllers use highly customized.

HTML

<input type="checkbox" id="chkincShowCancel" class="css-checkbox" name="incShowCancel" checkedValue="1" onclick="this.value = (this.checked==true ? 1 : 0)" style="border: 0;"/>
<label for="checkbox" class="css-label"></label>

But the checked / not checked changes doesn't get affected by the css. Any help on this.

Upvotes: 0

Views: 189

Answers (1)

Aditya Ponkshe
Aditya Ponkshe

Reputation: 3900

change your label to this

<label for="chkincShowCancel" class="css-label"></label>

id of your checkbox and for of your label should be the same

Upvotes: 4

Related Questions