Javascript 使用相同的CSS样式创建多个复选框
我想为同一HTML页面上的3个不同复选框使用CSS样式表。我不确定如何声明复选框的位置,使它们与文本一致。以下是复选框的CSS样式表:Javascript 使用相同的CSS样式创建多个复选框,javascript,jquery,html,css,checkbox,Javascript,Jquery,Html,Css,Checkbox,我想为同一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
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>
你吃早餐了吗?
你吃午饭了吗?
你吃晚饭了吗?
您可能可以尝试: HTML
让我们做一个适当的形式!现在就把你想要的弄清楚 正确答案看小提琴- HTML
使用像
span
这样的内联元素而不是div
,或者将div
设置为内联元素,与我的意思完全不同。我希望每个问题都在单独的行上,旁边有相应的复选框。我正在使用CSS来设置复选框的样式,因为这是针对移动应用程序的。现在看看小提琴,我改变了答案。这正是我想要的设置,但是有没有办法用我的CSS实现呢?我解决这个问题的方法是在CSS中创建两个新的复选框,并通过硬编码更改它们的位置,但这会有很多重复的代码,我想用一种更有效的方法来解决这个问题!这里:您可以在输入后摆弄css:after来获得您想要的表单。
<div class="row">
<input type="radio" /> <span>Radio title </span>
</div>
.row{ display:block;}
.row span{margin:0 0 0 10px;}
<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>
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;
}