我有一个复选框,虽然点击它什么也没做,但css似乎是正确的,除非有些事情发生了变化。它附加了一个类。
当我删除css时这会有效,尽管我认为'after'
上某处有错误https://jsfiddle.net/bLg5juxd/
.form-flat-radio,
.form-flat-checkbox {
margin: 0;
cursor: pointer;
display: block;
position: relative;
padding: 0 0 0 30px;
}
.dh-ie .form-flat-radio,
.dh-ie .form-flat-checkbox {
padding: 0;
}
.form-flat-radio input,
.form-flat-checkbox input {
left: -9999px;
position: absolute;
}
.dh-ie .form-flat-radio input,
.dh-ie .form-flat-checkbox input {
position: relative;
left: auto;
}
.form-flat-radio i,
.form-flat-checkbox i {
background: none repeat scroll 0 0 #fff;
border-style: solid;
border-width: 1px;
display: block;
height: 17px;
left: 0;
outline: medium none;
position: absolute;
top: 5px;
border-color: #d5d5d5;
width: 17px;
top: 50%;
margin-top: -8.5px;
color: #1e1e1e;
}
.dh-ie .form-flat-radio i,
.dh-ie .form-flat-checkbox i {
display: none;
}
.form-flat-radio i:after,
.form-flat-checkbox i:after {
opacity: 0;
filter: alpha(opacity=0);
-webkit-transition: opacity 0.1s ease 0s;
-o-transition: opacity 0.1s ease 0s;
transition: opacity 0.1s ease 0s;
}
<div class="form-flat-checkbox pull-left">
<input type="checkbox" name="rememberme" id="rememberme" value="forever"><i></i> Remember Me
</div>
答案 0 :(得分:3)
您需要将自定义输入和文本包装在设置了for
属性的标签中。
<div class="form-flat-checkbox pull-left">
<input type="checkbox" name="rememberme" id="rememberme" value="forever">
<label for="rememberme">
<i></i> Remember Me
</label>
</div>
在这种情况下,您还可以将按钮的样式更改为display: none;
。我个人更喜欢这种方法,而不是将其移出页面。此外,这提供了按下文本以触发复选框的好处。
.form-flat-radio input,
.form-flat-checkbox input {
display: none;
}
请参阅:https://jsfiddle.net/bLg5juxd/4/
.form-flat-radio,
.form-flat-checkbox {
margin: 0;
cursor: pointer;
display: block;
position: relative;
padding: 0 0 0 30px;
}
.dh-ie .form-flat-radio,
.dh-ie .form-flat-checkbox {
padding: 0;
}
.form-flat-radio input,
.form-flat-checkbox input {
display: none;
}
.dh-ie .form-flat-radio input,
.dh-ie .form-flat-checkbox input {
position: relative;
left: auto;
}
.form-flat-radio i,
.form-flat-checkbox i {
background: none repeat scroll 0 0 #fff;
border-style: solid;
border-width: 1px;
display: block;
height: 17px;
left: 0;
outline: medium none;
position: absolute;
top: 5px;
border-color: #d5d5d5;
width: 17px;
top: 50%;
margin-top: -8.5px;
color: #1e1e1e;
}
.dh-ie .form-flat-radio i,
.dh-ie .form-flat-checkbox i {
display: none;
}
.form-flat-radio i:after,
.form-flat-checkbox i:after {
opacity: 0;
filter: alpha(opacity=0);
-webkit-transition: opacity 0.1s ease 0s;
-o-transition: opacity 0.1s ease 0s;
transition: opacity 0.1s ease 0s;
}
.form-flat-radio input:checked + i:after,
.form-flat-checkbox input:checked + i:after {
opacity: 1;
background-color: red;
}
.form-flat-radio i {
-webkit-border-radius: 50%;
border-radius: 50%;
}
.form-flat-radio i:after {
-webkit-border-radius: 50%;
border-radius: 50%;
content: "";
height: 7px;
left: 4px;
top: 4px;
line-height: 1;
width: 7px;
position: absolute;
background: #1e1e1e;
}
.form-flat-checkbox i:after {
content: "\f00c";
position: relative;
display: inline-block;
font-family: "FontAwesome";
font-style: normal;
font-weight: normal;
line-height: 1;
text-decoration: inherit;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
speak: none;
}
.form-flat-checkbox i:after {
font-size: 12px;
height: 17px;
left: -1px;
text-align: center;
position: absolute;
top: 50%;
-webkit-transform: translate(0, -50%);
-ms-transform: translate(0, -50%);
-o-transform: translate(0, -50%);
transform: translate(0, -50%);
margin-top: 2px;
width: 17px;
opacity: 0;
filter: alpha(opacity=0);
line-height: 1;
}
&#13;
<div class="form-flat-checkbox pull-left">
<input type="checkbox" name="rememberme" id="rememberme" value="forever">
<label for="rememberme">
<i></i> Remember Me
</label>
</div>
&#13;
答案 1 :(得分:1)
你只需要用带有标签的文字包装你的文字就可以了。
<label for="rememberme">Remember Me</label>
.form-flat-radio,
.form-flat-checkbox {
margin: 0;
cursor: pointer;
display: block;
position: relative;
padding: 0 0 0 30px;
}
.dh-ie .form-flat-radio,
.dh-ie .form-flat-checkbox {
padding: 0;
}
.form-flat-radio input,
.form-flat-checkbox input {
left: -9999px;
position: absolute;
}
.dh-ie .form-flat-radio input,
.dh-ie .form-flat-checkbox input {
position: relative;
left: auto;
}
.form-flat-radio i,
.form-flat-checkbox i {
background: none repeat scroll 0 0 #fff;
border-style: solid;
border-width: 1px;
display: block;
height: 17px;
left: 0;
outline: medium none;
position: absolute;
top: 5px;
border-color: #d5d5d5;
width: 17px;
top: 50%;
margin-top: -8.5px;
color: #1e1e1e;
}
.dh-ie .form-flat-radio i,
.dh-ie .form-flat-checkbox i {
display: none;
}
.form-flat-radio i:after,
.form-flat-checkbox i:after {
opacity: 0;
filter: alpha(opacity=0);
-webkit-transition: opacity 0.1s ease 0s;
-o-transition: opacity 0.1s ease 0s;
transition: opacity 0.1s ease 0s;
}
.form-flat-radio input:checked + i:after,
.form-flat-checkbox input:checked + i:after {
opacity: 1;
filter: alpha(opacity=100);
background-color: red;
}
.form-flat-radio i {
-webkit-border-radius: 50%;
border-radius: 50%;
}
.form-flat-radio i:after {
-webkit-border-radius: 50%;
border-radius: 50%;
content: "";
height: 7px;
left: 4px;
top: 4px;
line-height: 1;
width: 7px;
position: absolute;
background: #1e1e1e;
}
.form-flat-checkbox i:after {
content: "\f00c";
position: relative;
display: inline-block;
font-family: "FontAwesome";
font-style: normal;
font-weight: normal;
line-height: 1;
text-decoration: inherit;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
speak: none;
}
.form-flat-checkbox i:after {
font-size: 12px;
height: 17px;
left: -1px;
text-align: center;
position: absolute;
top: 50%;
-webkit-transform: translate(0, -50%);
-ms-transform: translate(0, -50%);
-o-transform: translate(0, -50%);
transform: translate(0, -50%);
margin-top: 2px;
width: 17px;
opacity: 0;
filter: alpha(opacity=0);
line-height: 1;
}
&#13;
<div class="form-flat-checkbox pull-left">
<input type="checkbox" name="rememberme" id="rememberme" value="forever"><i></i> <label for="rememberme">Remember Me</label>
</div>
&#13;
答案 2 :(得分:1)
用标签包裹并与ID
.form-flat-radio,
.form-flat-checkbox {
margin: 0;
cursor: pointer;
display: block;
position: relative;
padding: 0 0 0 30px;
}
.dh-ie .form-flat-radio,
.dh-ie .form-flat-checkbox {
padding: 0;
}
.form-flat-radio input,
.form-flat-checkbox input {
left: -9999px;
position: absolute;
}
.dh-ie .form-flat-radio input,
.dh-ie .form-flat-checkbox input {
position: relative;
left: auto;
}
.form-flat-radio i,
.form-flat-checkbox i {
background: none repeat scroll 0 0 #fff;
border-style: solid;
border-width: 1px;
display: block;
height: 17px;
left: 0;
outline: medium none;
position: absolute;
top: 5px;
border-color: #d5d5d5;
width: 17px;
top: 50%;
margin-top: -8.5px;
color: #1e1e1e;
}
.dh-ie .form-flat-radio i,
.dh-ie .form-flat-checkbox i {
display: none;
}
.form-flat-radio i:after,
.form-flat-checkbox i:after {
opacity: 0;
filter: alpha(opacity=0);
-webkit-transition: opacity 0.1s ease 0s;
-o-transition: opacity 0.1s ease 0s;
transition: opacity 0.1s ease 0s;
}
.form-flat-radio input:checked + label i:after,
.form-flat-checkbox input:checked + label i:after {
opacity: 1;
filter: alpha(opacity=100);
background-color: red;
}
.form-flat-radio i {
-webkit-border-radius: 50%;
border-radius: 50%;
}
.form-flat-radio i:after {
-webkit-border-radius: 50%;
border-radius: 50%;
content: "";
height: 7px;
left: 4px;
top: 4px;
line-height: 1;
width: 7px;
position: absolute;
background: #1e1e1e;
}
.form-flat-checkbox i:after {
content: "\f00c";
position: relative;
display: inline-block;
font-family: "FontAwesome";
font-style: normal;
font-weight: normal;
line-height: 1;
text-decoration: inherit;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
speak: none;
}
.form-flat-checkbox i:after {
font-size: 12px;
height: 17px;
left: -1px;
text-align: center;
position: absolute;
top: 50%;
-webkit-transform: translate(0, -50%);
-ms-transform: translate(0, -50%);
-o-transform: translate(0, -50%);
transform: translate(0, -50%);
margin-top: 2px;
width: 17px;
opacity: 0;
filter: alpha(opacity=0);
line-height: 1;
}
<div class="form-flat-checkbox pull-left">
<input type="checkbox" name="rememberme" id="rememberme" value="forever">
<label for="rememberme"><i></i> Remember Me</label>
</div>
答案 3 :(得分:0)
您不需要标签标签只需更改此类属性:
.form-flat-radio input,
.form-flat-checkbox input {
left: 0;
position: absolute;
z-index: 1;
opacity: 0;
cursor: pointer;
}
.form-flat-radio,
.form-flat-checkbox {
margin: 0;
cursor: pointer;
display: block;
position: relative;
padding: 0 0 0 30px;
}
.form-flat-radio input,
.form-flat-checkbox input {
left: 0;
position: absolute;
z-index: 1;
opacity: 0;
cursor: pointer;
}
.form-flat-radio i,
.form-flat-checkbox i {
background: none repeat scroll 0 0 #fff;
border-style: solid;
border-width: 1px;
display: block;
height: 17px;
left: 0;
outline: medium none;
position: absolute;
top: 5px;
border-color: #d5d5d5;
width: 17px;
top: 50%;
margin-top: -8.5px;
color: #1e1e1e;
}
.form-flat-radio i:after,
.form-flat-checkbox i:after {
opacity: 0;
filter: alpha(opacity=0);
-webkit-transition: opacity 0.1s ease 0s;
-o-transition: opacity 0.1s ease 0s;
transition: opacity 0.1s ease 0s;
}
.form-flat-radio input:checked + i:after,
.form-flat-checkbox input:checked + i:after {
opacity: 1;
filter: alpha(opacity=100);
background-color: red;
}
.form-flat-radio i {
-webkit-border-radius: 50%;
border-radius: 50%;
}
.form-flat-radio i:after {
-webkit-border-radius: 50%;
border-radius: 50%;
content: "";
height: 7px;
left: 4px;
top: 4px;
line-height: 1;
width: 7px;
position: absolute;
background: #1e1e1e;
}
.form-flat-checkbox i:after {
content: "\f00c";
position: relative;
display: inline-block;
font-family: "FontAwesome";
font-style: normal;
font-weight: normal;
line-height: 1;
text-decoration: inherit;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
speak: none;
}
.form-flat-checkbox i:after {
font-size: 12px;
height: 17px;
left: -1px;
text-align: center;
position: absolute;
top: 50%;
-webkit-transform: translate(0, -50%);
-ms-transform: translate(0, -50%);
-o-transform: translate(0, -50%);
transform: translate(0, -50%);
margin-top: 2px;
width: 17px;
opacity: 0;
filter: alpha(opacity=0);
line-height: 1;
}
&#13;
<div class="form-flat-checkbox pull-left">
<input type="checkbox" name="rememberme" id="rememberme" value="forever">
<i></i> Remember Me
</div>
&#13;