我彼此之间有两个自定义的单选按钮。但是它在前三个类型中具有前面的类型和标题。两者都在CSS中带有display: inline-block;
,但单选按钮仍位于文本块下方。我不知道如何像其他人那样让它们彼此相邻。
/*radio button yes no*/
.switch-field {
font-family: "Lucida Grande", Tahoma, Verdana, sans-serif;
padding: 40px;
overflow: hidden;
margin-left: 225px;
}
.switch-field input {
position: absolute !important;
clip: rect(0, 0, 0, 0);
height: 1px;
width: 1px;
border: 0;
overflow: hidden;
}
.switch-field label {
float: left;
}
.switch-field label {
display: inline-block;
width: 100px;
background-color: white;
color: rgba(0, 0, 0, 0.6);
font-size: 14px;
font-weight: normal;
text-align: center;
text-shadow: none;
padding: 6px 14px;
border: 1px solid #b70000;
-webkit-transition: all 0.1s ease-in-out;
-moz-transition: all 0.1s ease-in-out;
-ms-transition: all 0.1s ease-in-out;
-o-transition: all 0.1s ease-in-out;
transition: all 0.1s ease-in-out;
}
.switch-field label:hover {
cursor: pointer;
}
.switch-field input:checked + label {
background-color: #b70000;;
color:white;
}
.switch-field label:first-of-type {
border-radius: 0px 0 0 0px;
}
.switch-field label:last-of-type {
border-radius: 0 0px 0px 0;
}
/*radio button yes no*/
/*block*/
.block label { display: inline-block; width: 140px; text-align: right; }
<div class="CalculatorLeft" style="padding-left: 29px;"id="alles">
<h2 style="color:#b70000;">Bereken Prijs</h2>
<div class="block">
<label>Aantal vierkante meters</label>
<input type="text" style="border:0px;border-bottom:1px solid #b70000;margin-left: 92px;width:200px;" />
</div><br>
<div class="block">
<label>V-naden aanwezig</label>
<select name="cars" class="" style="border:0px;border-bottom:1px solid #b70000;margin-left: 128px;width:200px;">
<option value="behandeling" selected>Soort behandeling</option>
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="fiat">Fiat</option>
<option value="audi">Audi</option>
</select>
</div><br>
<div class="block">
<label>Soort behandeling</label>
<div class="switch-field">
<input type="radio" id="switch_left" name="switch_2" value="yes" checked/>
<label for="switch_left">Yes</label>
<input type="radio" id="switch_right" name="switch_2" value="no" />
<label for="switch_right">No</label>
</div>
</div><br>
<div class="block">
<label>Postcode & Huisnummer</label>
<input type="text" style="border:0px;border-bottom:1px solid #b70000;margin-left: 89px;width:200px;" />
</div>
</div>
答案 0 :(得分:1)
您应该尝试删除“ yes / no”单选输入的父元素上的所有边距和填充,因为此“容器”使元素远离标签。
有关解决方案,请参见代码段:
/*radio button yes no*/
.switch-field {
font-family: "Lucida Grande", Tahoma, Verdana, sans-serif;
/*padding: 40px;*/
overflow: hidden;
/*margin-left: 225px;*/
display: inline-block;
vertical-align: middle;
}
.switch-field input {
position: absolute !important;
clip: rect(0, 0, 0, 0);
height: 1px;
width: 1px;
border: 0;
overflow: hidden;
}
.switch-field label {
float: left;
}
.switch-field label {
display: inline-block;
width: 100px;
background-color: white;
color: rgba(0, 0, 0, 0.6);
font-size: 14px;
font-weight: normal;
text-align: center;
text-shadow: none;
padding: 6px 14px;
border: 1px solid #b70000;
-webkit-transition: all 0.1s ease-in-out;
-moz-transition: all 0.1s ease-in-out;
-ms-transition: all 0.1s ease-in-out;
-o-transition: all 0.1s ease-in-out;
transition: all 0.1s ease-in-out;
}
.switch-field label:hover {
cursor: pointer;
}
.switch-field input:checked+label {
background-color: #b70000;
;
color: white;
}
.switch-field label:first-of-type {
border-radius: 0px 0 0 0px;
}
.switch-field label:last-of-type {
border-radius: 0 0px 0px 0;
}
/*radio button yes no*/
.block label {
display: inline-block;
width: 140px;
text-align: right;
}
<div class="CalculatorLeft" style="padding-left: 29px;" id="alles">
<h2 style="color:#b70000;">Bereken Prijs</h2>
<div class="block">
<label>Aantal vierkante meters</label>
<input type="text" style="border:0px;border-bottom:1px solid #b70000;margin-left: 92px;width:200px;" />
</div><br>
<div class="block">
<label>V-naden aanwezig</label>
<select name="cars" class="" style="border:0px;border-bottom:1px solid #b70000;margin-left: 128px;width:200px;">
<option value="behandeling" selected>Soort behandeling</option>
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="fiat">Fiat</option>
<option value="audi">Audi</option>
</select>
</div><br>
<div class="block">
<label>Soort behandeling</label>
<div class="switch-field">
<input type="radio" id="switch_left" name="switch_2" value="yes" checked/>
<label for="switch_left">Yes</label>
<input type="radio" id="switch_right" name="switch_2" value="no" />
<label for="switch_right">No</label>
</div>
</div><br>
<div class="block">
<label>Postcode & Huisnummer</label>
<input type="text" style="border:0px;border-bottom:1px solid #b70000;margin-left: 89px;width:200px;" />
</div>
</div>
看看您的.switch-field
类中是否有更改。您也可以在其上添加页边空白以正确定位。如果您需要更多帮助,请告诉我。
答案 1 :(得分:1)
尝试一下;
CSS
.switch-field {
font-family: "Lucida Grande", Tahoma, Verdana, sans-serif;
padding: 0px;
overflow: hidden;
margin-left: 95px;
display: inline-block;
vertical-align: middle;
}