html - 无法在CSS中设计复选框

标签 html css

我有一些复选框列表,我试图对其进行自定义设计。但是我的编码不起作用。这是我的示例代码:

我的 CSS 是:

input[type="checkbox"]{
display:none;
}
input[type="checkbox"] + span{
width:15px;
height:15px;
background:url(../img/uncheck_box.png) no-repeat;
display:inline-block;
}
input[type="checkbox"]:checked + span{
background:url(../img/check_box.png) no-repeat;
}

我的 HTML 是:

<input type="checkbox" id="1" /><span></span><label for="1">AAAA</label><br />
<input type="checkbox" id="2" /><span></span><label for="2">BBBB</label><br />
<input type="checkbox" id="3" /><span></span><label for="3">CCCC</label><br />
<input type="checkbox" id="4" /><span></span><label for="4">DDDD</label><br />
<input type="checkbox" id="5" /><span></span><label for="5">EEEE</label><br />
<input type="checkbox" id="6" /><span></span><label for="6">FFFF</label>

最佳答案

<html lang="en">
<head>
<meta charset="utf-8" />
<title>jQuery UI Button - Checkboxes</title>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.2/themes/smoothness/jquery-ui.css" />
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.2/jquery-ui.js"></script>
<link rel="stylesheet" href="/resources/demos/style.css" />
<script>
$(function() {
$( "#check" ).button();
$( "#format" ).buttonset();
});
</script>
<style>
#format { margin-top: 2em; }
</style>
</head>
<body>
<input type="checkbox" id="check" /><label for="check">Toggle</label>
<div id="format">
<input type="checkbox" id="check1" /><label for="check1">B</label>
<input type="checkbox" id="check2" /><label for="check2">I</label>
<input type="checkbox" id="check3" /><label for="check3">U</label>
</div>
</body>
</html>

我认为你需要这个:这是最好的练习。

关于html - 无法在CSS中设计复选框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15546134/

相关文章:

javascript - 如何使用手机间隙在html5中录制音频

html - 如何使用 css 单独打印页面中的多个元素?

javascript - 如何自定义 Bootstrap 工具提示弹出框的文本字体大小?

css - @font-face 在 Chrome/IE 中渲染更大,fontsquirrel

javascript - 如何模拟点击事件以延迟循环播放幻灯片

javascript - Angular - 没有可排序的方法

css - Bootstrap 4 - 折叠导航栏的样式

javascript - jQuery 下拉菜单不工作

javascript - 从元素输入填写时自动调整文本区域大小 - Javascript

html - 水平 3 个 div,将最后一个高度设置为 auto