【发布时间】:2016-12-26 02:05:50
【问题描述】:
我有一个checkbox,用于表格和我的网络应用程序的其他部分。
此复选框位于 DIV 内,因此具有更好的外观和感觉。
HTML中的复选框是这样形成的:
<div class="checkbox checkbox-success checkbox-single">
<input type="checkbox"><label></label>
</div>
我检测到,当我单击复选框的中心时,它可以工作,但如果我在左上角、右上角或左下角进行检查,则它不起作用。
然后我检查Google chrome 中的元素,当我选择input 元素时发现了这个。
这就是它不起作用的原因,因为输入元素没有以 div 为中心。
我正在使用 Bootstrap 3。
这是我在选择 input 元素时可以在 Google chrome 检查器中看到的 CSS。
这是CSS 我猜是从我的Style.css 应用的
.checkbox {
padding-left: 20px;
}
.checkbox label {
display: inline-block;
padding-left: 5px;
position: relative;
}
.checkbox label::before {
-o-transition: 0.3s ease-in-out;
-webkit-transition: 0.3s ease-in-out;
background-color: #ffffff;
border-radius: 3px;
border: 1px solid #cccccc;
content: "";
display: inline-block;
height: 17px;
left: 0;
margin-left: -20px;
position: absolute;
transition: 0.3s ease-in-out;
width: 17px;
outline: none !important;
}
.checkbox input[type="checkbox"] {
cursor: pointer;
opacity: 0;
z-index: 1;
outline: none !important;
}
.checkbox label::after {
color: #555555;
display: inline-block;
font-size: 11px;
height: 16px;
left: 0;
margin-left: -20px;
padding-left: 3px;
padding-top: 1px;
position: absolute;
top: 0;
width: 16px;
}
.checkbox.checkbox-single label {
height: 17px;
}
.checkbox-success input[type="checkbox"]:checked + label::before {
background-color: #01ba9a;
border-color: #01ba9a;
}
.checkbox-success input[type="checkbox"]:checked + label::after {
color: #ffffff;
}
这是一个CodePen 示例,不显示相同的确切位置,但您会看到输入未居中对齐。
http://codepen.io/anon/pen/Jbqapo
这让我头疼,有什么线索吗?
【问题讨论】:
-
你能用 fiddle 或 sn-p 解决你的问题吗?
-
我只是添加了一个指向 CodePen 的链接,您可以在其中看到类似的行为。
标签: css checkbox twitter-bootstrap-3