使用相同的CSS样式创建多个复选框
Create multiple checkboxes using the same CSS style
我想对同一HTML页面上的3个不同复选框使用CSS样式表。我不确定如何声明复选框的位置,使它们与文本一致。这是我的复选框CSS样式表:
input[type=checkbox]
{
visibility: hidden;
}
.checkboxOne {
background: none repeat scroll 0 0 #484848;
border-radius: 100%;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
height: 40px;
margin: -30px 200px;
position: relative;
width: 40px;
}
.checkboxOne input[type="checkbox"]:checked + label {
background: none repeat scroll 0 0 #6E0000;
}
.checkboxOne label:before {
content:'N';
padding:6px;
color:#000000;
display: block;
padding: 4px;
text-align: center;
}
.checkboxOne input[type="checkbox"]:checked + label:before {
content:'Y';
padding:6px;
color:#FFFFFF;
display:block;
padding: 4px;
text-align: center;
}
.checkboxOne label {
background: none repeat scroll 0 0 #DDDDDD;
border-radius: 100px;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.5) inset;
cursor: pointer;
display: block;
height: 30px;
left: 5px;
position: absolute;
top: 5px;
transition: all 0.5s ease 0s;
width: 30px;
z-index: 1;
}
我知道边距是硬编码复选框的位置。我希望有一种方法可以使复选框的位置直接位于html文档中的文本之后,如下所示:
Did you eat breakfast? <div class="checkboxOne">
<input type="checkbox" value="1" id="checkboxInput" name="" />
<label for="checkboxInput"></label>
</div><br>
Did you eat lunch? <div class="checkboxOne">
<input type="checkbox" value="1" id="checkboxInput2" name="" />
<label for="checkboxInput2"></label>
</div><br>
Did you eat dinner? <div class="checkboxOne">
<input type="checkbox" value="1" id="checkboxInput3" name="" />
<label for="checkboxInput3"></label>
</div><br>
让我们做一个正确的形式!现在就把你想要的东西整理好。
正确答案看看小提琴-http://jsfiddle.net/Wa5s8/2/
HTML
<form>
<fieldset>
<input type="checkbox" value="1" id="checkboxInput" name="" />
<label for="checkboxInput">Did you eat breakfast?</label>
<input type="checkbox" value="1" id="checkboxInput2" name="" />
<label for="checkboxInput2">Did you eat lunch?</label>
<input type="checkbox" value="1" id="checkboxInput3" name="" />
<label for="checkboxInput3">Did you eat dinner?</label>
</fieldset>
</form>
少量CSS:
input[type=checkbox] {
display:none;
}
label {
float: left;
clear: left;
width: 200px;
}
input[type=checkbox] + label:after
{
content: 'N';
background: #F00;
float: right;
}
input[type=checkbox]:checked + label:after
{
content: 'Y';
background: #FF0;
}
您可以尝试:HTML
<div class="row">
<input type="radio" /> <span>Radio title </span>
</div>
CSS:
.row{ display:block;}
.row span{margin:0 0 0 10px;}
相关文章:
- 在JavaScript中动态创建复选框
- 基于表中的列动态创建复选框
- 为xml谷歌地图生成的每个标记创建复选框
- 将“已创建”复选框设置为选中不起作用
- extjs 3.4使用combo store创建复选框组项目
- 从AJAX响应动态创建复选框
- 使用Font Awesome与AngularJs创建复选框
- 使用Bootstrap Glyphicons创建复选框功能
- Javascript 已创建复选框未正确关闭标记
- 从数组列表java中动态创建复选框
- 动态创建复选框单击事件,选择整行,而不仅仅是jquery数据表中的复选框.为什么呢?
- 应用iCheck (jQuery插件)来动态创建复选框
- 动态创建复选框;在ExtJS中点击按钮不会被选中
- 用javascript创建复选框
- 在XUL中使用DOM JavaScript动态创建复选框
- 创建复选框
- 可以在组合框中创建复选框
- 如何使用Jquery动态创建复选框
- 如何通过函数创建复选框
- 如何创建复选框的角度模式表单检查表