我在单选按钮之间有大约30px的垂直空间。将margin-top
和margin-bottom
设置为0px
无效。如何消除垂直空间?
body {
margin: 2em;
font-family: Arial, Helvetica, sans-serif;
}
input[type="radio"] {
opacity: 0;
}
input[type="radio"]+label {
cursor: pointer;
border: 1px solid #ccc;
background: #efefef;
color: #aaa;
border-radius: 3px;
text-shadow: 1px 1px 0 rgba(0, 0, 0, 0);
display: block;
width: 200px;
height: 40px;
padding-left: 20px;
margin-top: 0px;
margin-bottom: 0px;
}
input[type="radio"]:checked+label {
background: #777;
border: 1px solid #444;
text-shadow: 1px 1px 0 rgba(0, 0, 0, 0.4);
color: white;
margin-top: 0px;
margin-bottom: 0px;
}

<input id="Radio1" name="Radios" type="radio">
<label for="Radio1">I am option1</label>
<input id="Radio2" name="Radios" type="radio" value="Option 2">
<label for="Radio2">I am option2</label>
<input id="Radio3" name="Radios" type="radio" value="Option 3">
<label for="Radio3">I am option3</label>
&#13;
答案 0 :(得分:2)
如果您的目的是隐藏单选按钮本身并且只显示标签,那么只需应用position: absolute
将其从页面流中删除:
input[type="radio"] {
opacity: 0;
position: absolute;
}
答案 1 :(得分:1)
将其从流程中移除(绝对) https://jsfiddle.net/0d227oj6/1/
body {
margin: 2em;
font-family: Arial, Helvetica, sans-serif;
}
input[type="radio"] {
opacity: 0;
position:absolute;/* removed from the flow */
}
input[type="radio"]+label {
cursor: pointer;
border: 1px solid #ccc;
background: #efefef;
color: #aaa;
border-radius: 3px;
text-shadow: 1px 1px 0 rgba(0, 0, 0, 0);
display: block;
width: 200px;
height: 40px;
padding-left: 20px;
margin-top: 0px;
margin-bottom: 0px;
}
input[type="radio"]:checked+label {
background: #777;
border: 1px solid #444;
text-shadow: 1px 1px 0 rgba(0, 0, 0, 0.4);
color: white;
margin-top: 0px;
margin-bottom: 0px;
}
&#13;
<input id="Radio1" name="Radios" type="radio">
<label for="Radio1">I am option1</label>
<input id="Radio2" name="Radios" type="radio" value="Option 2">
<label for="Radio2">I am option2</label>
<input id="Radio3" name="Radios" type="radio" value="Option 3">
<label for="Radio3">I am option3</label>
&#13;
答案 2 :(得分:1)
只需隐藏实际的单选按钮。
input[type="radio"] {
display: none;
}