自订复选框问题

时间:2013-12-05 05:13:45

标签: html css html5 css3

我使用教程开发了一个自定义复选框。代码如下。

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;
}

我尝试将上述css插入我现有的应用程序,其中控制器使用高度自定义。

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>

但是检查/未检查的更改不会受到css的影响。对此有任何帮助。

1 个答案:

答案 0 :(得分:4)

将您的标签更改为此

<label for="chkincShowCancel" class="css-label"></label>
您的复选框的

id和标签的for应该相同