我在使用相应的文字定位这些复选框时遇到了一些麻烦。
隐藏了实际的复选框,以便可以使用个人风格。
无论如何,这纯粹是一个CSS问题。文本应位于复选框的前面。
我一直把头撞在墙上,无法做到......
我错过了什么?
感谢。
HTML:
<div id="navigation">
<form id="catform" action="#">
<div class="kat1">
<label>
<input id="catswitch1" type="checkbox" onclick="shCat(1);" checked="checked"/><label for="thing" style="cursor: pointer"></label>
</div>
<div>ITEM 1</div>
<div class="kat2">
<label>
<input id="catswitch2" type="checkbox" onclick="shCat(2);"/><label for="thing" style="cursor: pointer"></label>
</div>
<div>ITEM 2</div>
<div class="kat8">
<label>
<input id="catswitch8" type="checkbox" onclick="shCat(8);"/><label for="thing" style="cursor: pointer"></label>
</div>
<div>ITEM 3</div>
</form>
</div>
CSS:
body {
font-family: Arial, Helvetica, san-serif;
font-size: 11px;
line-height: 15px;
}
#navigation {
left: 10px; top: 10px;
width: 120px;
border: 1px solid #000;
}
#navigation div {
padding: 1px 4px 3px 1px;
border: 1px none #000;
margin: 0 10px 4px 0;
height: 17px;
width: 100%;
}
input[type=checkbox] {
display:none;
}
input[type=checkbox] + label {
background: #FFF;
height: 11px;
width: 11px;
display:inline-block;
padding: 0 0 0 0px;
border: 1px solid #000;
}
input[type=checkbox]:checked + label {
background: #000;
height: 11px;
width: 11px;
display:inline-block;
padding: 0 0 0 0px;
border: 1px solid #000;
}
答案 0 :(得分:1)
该文字放在新闻div
内。 div
占据了整个空间,特别是在一条新线上。摆脱它。而是将它们放在span
中,也放在父级内,如下所示:
<div class="kat1">
<label>
<input id="catswitch1" type="checkbox" onclick="shCat(1);" checked="checked"/>
<label for="thing" style="cursor: pointer"></label>
</label>
<span>ITEM 1</span>
</div>
body {
font-family: Arial, Helvetica, san-serif;
font-size: 11px;
line-height: 15px;
}
#navigation {
left: 10px;
top: 10px;
width: 120px;
border: 1px solid #000;
}
#navigation div {
padding: 1px 4px 3px 1px;
border: 1px none #000;
margin: 0 10px 4px 0;
height: 17px;
width: 100%;
}
input[type=checkbox] {
display:none;
}
input[type=checkbox] + label {
background: #FFF;
height: 11px;
width: 11px;
display:inline-block;
padding: 0 0 0 0px;
border: 1px solid #000;
}
input[type=checkbox]:checked + label {
background: #000;
height: 11px;
width: 11px;
display:inline-block;
padding: 0 0 0 0px;
border: 1px solid #000;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="navigation">
<form id="catform" action="#">
<div class="kat1">
<label>
<input id="catswitch1" type="checkbox" onclick="shCat(1);" checked="checked" />
<label for="thing" style="cursor: pointer"></label>
</label>
<span>ITEM 1</span>
</div>
<div class="kat2">
<label>
<input id="catswitch2" type="checkbox" onclick="shCat(2);" />
<label for="thing" style="cursor: pointer"></label>
</label>
<span>ITEM 2</span>
</div>
<div class="kat8">
<label>
<input id="catswitch8" type="checkbox" onclick="shCat(8);" />
<label for="thing" style="cursor: pointer"></label>
</label>
<span>ITEM 3</span>
</div>
<div class="kat14">
<label>
<input id="catswitch14" type="checkbox" onclick="shCat(14);" />
<label for="thing" style="cursor: pointer"></label>
</label>
<span>ITEM 4</span>
</div>
<div class="kat9">
<label>
<input id="catswitch9" type="checkbox" onclick="shCat(9);" />
<label for="thing" style="cursor: pointer"></label>
</label>
<span>ITEM 5</span>
</div>
</form>
</div>
答案 1 :(得分:0)
答案 2 :(得分:0)
https://jsfiddle.net/b6aywnok/
CSS:
body {
font-family: Arial, Helvetica, san-serif;
font-size: 11px;
line-height: 15px;
}
#navigation {
left: 10px; top: 10px;
width: 120px;
border: 1px solid #000;
}
#navigation div {
padding: 1px 4px 3px 1px;
border: 1px none #000;
margin: 0 10px 4px 0;
height: 17px;
width: 100%;
}
input[type=checkbox] {
display:none;
}
input[type=checkbox] + label {
background: #FFF;
height: 11px;
margin-left:100px;
width: 11px;
display:inline-block;
padding: 0 0 0 0px;
border: 1px solid #000;
}
input[type=checkbox]:checked + label {
background: #000;
height: 11px;
width: 11px;
display:inline-block;
padding: 0 0 0 0px;
border: 1px solid #000;
}
h3
{
margin-left:50px;
margin-top:-25px;
}
HTML:
<body>
<div id="navigation">
<form id="catform" action="#">
<div class="kat1">
<label>
<input id="catswitch1" type="checkbox" onclick="shCat(1);" checked="checked"/><label for="thing" style="cursor: pointer"></label>
</div>
<h3>ITEM 1</h3>
<div class="kat2">
<label>
<input id="catswitch2" type="checkbox" onclick="shCat(2);"/><label for="thing" style="cursor: pointer"></label>
</div>
<h3>ITEM 2</h3>
<div class="kat8">
<label>
<input id="catswitch8" type="checkbox" onclick="shCat(8);"/><label for="thing" style="cursor: pointer"></label>
</div>
<h3>ITEM 3</h3>
</form>
</div>
</body>