【发布时间】:2018-09-21 10:26:23
【问题描述】:
有没有人已经设计了带有字体很棒的 5 个图标的复选框?
我已经用谷歌搜索过了,只找到了 FA-4 的示例,例如 http://flatlogic.github.io/awesome-bootstrap-checkbox/demo/
我更新到 FA5 并使用 CSS 伪元素运行其他东西,但在复选框内它没有运行。我对没有伪元素的其他解决方案持开放态度。
提前致谢!
小提琴示例:
/* Checkboxes */
.checkbox input[type="checkbox"] {
display: none;
}
.checkbox label {
padding-left: 0;
}
.checkbox label:before {
content: "";
width: 20px;
height: 20px;
display: inline-block;
vertical-align: bottom;
margin-right: 10px;
line-height: 20px;
text-align: center;
border: 1px solid #ccc;
box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075);
font-family: "FontAwesome";
}
.checkbox input[type="checkbox"]:checked+label::before {
content: "\f00c";
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<div class="checkbox">
<input type="checkbox" id="profile_notifications" value="" checked/>
<label for="profile_notifications">
I agree
</label>
</div>
/* Checkboxes */
.checkbox {
padding-left: 10px;
padding-top: 10px;
}
.checkbox input[type="checkbox"] {
display: none;
}
.checkbox label {
padding-left: 0;
}
.checkbox label:before {
content: "";
width: 20px;
height: 20px;
display: inline-block;
vertical-align: bottom;
margin-right: 10px;
line-height: 20px;
text-align: center;
border: 1px solid #ccc;
box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075);
font-family: "Font Awesome 5 Solid";
}
.checkbox input[type="checkbox"]:checked+label::before {
font-family: "Font Awesome 5 Solid";
content: "\f00c";
}
.test {
padding-left: 10px;
padding-top: 10px;
}
.test .pseudo-element:before {
display: none;
font-family: "Font Awesome 5 Solid";
content: "\f00c";
}
<script defer src="https://use.fontawesome.com/releases/v5.0.10/js/all.js" integrity="sha384-slN8GvtUJGnv6ca26v8EzVaR9DC58QEwsIk9q1QXdCU8Yu8ck/tL/5szYlBbqmS+" crossorigin="anonymous"></script>
<script>
window.FontAwesomeConfig = {
searchPseudoElements: true
}
</script>
<div class="checkbox">
<input type="checkbox" id="profile_notifications" value="" checked/>
<label for="profile_notifications">
Doesn't work!
</label>
</div>
<div class="test">
<label class="pseudo-element">This works!</label>
</div>
【问题讨论】:
-
你能展示你为复选框做了什么吗?目前尚不完全清楚您的要求...
-
是的,当然!我编辑了我的帖子!
-
谢谢 - 这让重现/理解问题变得更加容易,也完全消除了投票结束问题的原因。通常这些伪元素需要一个
display: none;(就像你为工作元素设置的那样),但是当我们将它添加到 `.checkbox input[type="checkbox"]:checked+label::before` 时,它会显示很好,但是复选框消失了,所以没有办法取消选中复选框,我没有解决方案。也许其他人会加入...... -
这是一个 Fiddle,它还可以用几行 CSS 设置单选按钮的样式:jsfiddle.net/z2mxtk7g
标签: css font-awesome pseudo-element font-awesome-5