如何在同一行上回显某些输出(单选按钮)



由于标签输出即将出现在下一行

while ($row=mysqli_fetch_array($res))
{ 
echo  "<label for='A'> <input type='radio' class='muted pull-left' name ='radio' id='A' value=".$row['dis'].">&nbsp;".$row['dis']."</label>";             
}

输出应为:

Radio button 1   Radio button 2 .....  Radio button n

这是一个CSS问题。使<label>标签display:inline

在样式标签中使用下面给出的 CSS

字段集 {

溢出:隐藏

}

.some-class {

浮点:左;

清除:无;

}

标签 {

浮点:左;

清除:无;

显示:块;

填充:2px 1em 0 0;

}

输入[类型=无线电],

输入无线电 {

浮点:左;

清除:无;

边距: 2px 00 2px;

}

正如@cweiske所说,CSS似乎是问题所在。没有任何 CSS 更改的输出应该是内联的,但您的输出似乎 https://jsfiddle.net/qam2sxy5/是块格式。 尝试

while ($row=mysqli_fetch_array($res))
{ 
echo  "<label for='A' style="display:inline"> <input style="display:inline-block" type='radio' class='muted pull-left' name 
='radio' id='A' value=".$row['dis'].">&nbsp;".$row['dis']."</label>";             
}

不要将输入放在标签内。此外,单选按钮没有值。选中或未选中。

<div class="row">
<label for='A'>Label A</label>
<input type='radio' class='muted pull-left' name='radio' value='A' id='A' />
<label for='B'>Label B</label>
<input type='radio' class='muted pull-left' name='radio' value='B' id='B' />
<label for='C'>Label C</label>
<input type='radio' class='muted pull-left' name='radio' value='C' id='C' checked />
</div>

最新更新