gpt4 book ai didi

jquery - 如何定位复选框和文本

转载 作者:太空宇宙 更新时间:2023-11-04 12:12:24 27 4
gpt4 key购买 nike

我在定位这些复选框及其各自的文本时遇到了一些问题。

隐藏了实际的复选框,以便可以使用个人风格。

无论如何,这纯粹是一个 CSS 问题。文本应位于复选框的前面。

我一直在用头撞墙,做不到...

我错过了什么?

谢谢。

JSFiddle

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;
}

最佳答案

文本放在新闻 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>

关于jquery - 如何定位复选框和文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28949470/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com