小编amy*_*yyy的帖子

如何使整个自定义复选框/ Div可点击 - 不仅仅是标签+输入

我有自定义复选框,我的样式像按钮.单击标签或输入div时,它会改变颜色.但是,只有标签和输入是可点击的.

有没有办法让整个div /按钮可以点击(即边框内的所有内容)?

这是我的代码:

div.label {  
    border:solid 1px gray;
    line-height:40px;
    height:40px;
    width: 250px;
    border-radius:40px;
    -webkit-font-smoothing: antialiased; 
    margin-top:10px;
    font-family:Arial,Helvetica,sans-serif;
    color:gray;
    text-align:center;
}

label {
    display:inline;
    text-align:center;
}

input[type=checkbox] {
    display: none;
}

input:checked + div {
    border: solid 1px red;
    color: #F00;
}

input:checked + div:before {
    content: "\2713";
}
Run Code Online (Sandbox Code Playgroud)
<input id="lists[Travel]" type="checkbox" name="lists[Travel]" />
<div class="label">
    <label for="lists[Travel]">Travel</label> <br>
</div>
Run Code Online (Sandbox Code Playgroud)

html css checkbox

9
推荐指数
2
解决办法
1万
查看次数

标签 统计

checkbox ×1

css ×1

html ×1