Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/38.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/github/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 单选按钮对齐问题_Html_Css_Radio Button - Fatal编程技术网

Html 单选按钮对齐问题

Html 单选按钮对齐问题,html,css,radio-button,Html,Css,Radio Button,如何使单选按钮更靠近标签 input[type="radio"]{ float: left; width: auto; margin-left: 3em; } <fieldset id="payment_method"> <legend>Payment Method</legend> <input type="radio" name="payment_method"value="Bill Me"> <label for=

如何使单选按钮更靠近标签

input[type="radio"]{
   float: left;
   width: auto;
   margin-left: 3em;
}

<fieldset id="payment_method">
<legend>Payment Method</legend>
<input type="radio" name="payment_method"value="Bill Me">
<label for= "payment1"> Bill Me</label>
<input type="radio" name="payment_method"value="Bill Me">
<label for= "payment2">Credit Card</label>
</fieldset>
input[type=“radio”]{
浮动:左;
宽度:自动;
左边距:3em;
}
付款方式
给我开账单
信用卡

您不需要浮动输入,只需给标签一个负边距即可,如下所示:

label {
margin-left: -1px;
}

只是不要对你的无线电输入应用任何规则。由于所有表单元素都是非块级元素(不包括
表单
本身),因此您不需要
浮动它们(在您的情况下)并删除额外的
边距
。见


我喜欢将输入/标签对包装在
中,以简化样式设置。之后,您可以删除标签和输入标记之间的换行符:

<fieldset id="payment_method">
  <legend>Payment Method</legend>
  <div class="fieldgroup">
    <input type="radio" name="payment_method"value="Bill Me"><label for= "payment1">Bill Me</label>
  </div><!--/.fieldgroup-->
  <div class="fieldgroup">
    <input type="radio" name="payment_method"value="Bill Me"><label for= "payment2">Credit Card</label>
  </div><!--/.fieldgroup-->
</fieldset>

对不起,我看到小提琴了,但我不明白。如果输入[type=“radio”]中没有样式,它们将再次垂直对齐。
<fieldset id="payment_method">
  <legend>Payment Method</legend>
  <div class="fieldgroup">
    <input type="radio" name="payment_method"value="Bill Me"><label for= "payment1">Bill Me</label>
  </div><!--/.fieldgroup-->
  <div class="fieldgroup">
    <input type="radio" name="payment_method"value="Bill Me"><label for= "payment2">Credit Card</label>
  </div><!--/.fieldgroup-->
</fieldset>
input[type='radio'],
label {
  float: left;
}
.fieldgroup:after {
  content: "";
  display: block;
  clear: both;
}