【发布时间】:2014-02-04 05:47:31
【问题描述】:
我正在尝试构建一组自定义复选框,这些复选框在选中时会更改标签颜色和背景。
基本上我试图综合这两个想法:
1) 将数字放在圆圈内How to use CSS to surround a number with a circle?
2) 使用 span 和 ":checked" 属性创建自定义复选框 http://webdesign.tutsplus.com/tutorials/htmlcss-tutorials/quick-tip-easy-css3-checkboxes-and-radio-buttons/
到目前为止,我还没有弄清楚如何让一个由 ':checked' 状态控制的标签放在复选框的中间。
这是我到目前为止的进展: http://jsfiddle.net/Cg9eX/
css
input[type="checkbox"] {
display:none;
}
input[type="checkbox"] + label span {
display:inline-block;
width:30px;
height:30px;
margin: 0 4px 0 0;
vertical-align:middle;
background: none;
cursor:pointer;
line-height: 14px;
text-align: center;
border: solid 1px #000000;
-moz-border-radius: 50%;
-webkit-border-radius: 50%;
border-radius: 50%;
}
input[type="checkbox"]:checked + label span {
background-color: rgba(153, 153, 153, .7);
border: none;
}
input[type="checkbox"]:checked + label {
color: white;
}
html
<input type="checkbox" id="c1" name="cc" />
<label for="c1"><span></span>4</label>
【问题讨论】:
-
很好的回应。现在唯一的问题是数字居中的跨浏览器问题 - Chrome、Firefox、IE 等的 line-height 似乎不同。