将单选按钮彼此左对齐的最佳方法是什么?
我有一堆单选按钮,
<br/>
每个按钮后面都有一个,它们似乎都水平居中对齐(即使我放置了一些表示左对齐的CSS)。
这是 CSS,
.radioLeft
{
text-align:left;
}
这是 HTML:
<input checked="checked" class="radioLeft" name="CalendarType" value="1" type="radio"><b>Person </b>(False) <br>
<input checked="checked" class="radioLeft" name="CalendarType" value="2" type="radio"><b>Event </b>(False) <br>
<input checked="checked" class="radioLeft" name="CalendarType" value="3" type="radio"><b>Release</b>(False) <br>
I have a bunch of radio buttons, and I have a
<br/>
after each one and they all seem to horizontal align center (even if I put some CSS that says left align).
Here is the CSS,
.radioLeft
{
text-align:left;
}
Here is the HTML:
<input checked="checked" class="radioLeft" name="CalendarType" value="1" type="radio"><b>Person </b>(False) <br>
<input checked="checked" class="radioLeft" name="CalendarType" value="2" type="radio"><b>Event </b>(False) <br>
<input checked="checked" class="radioLeft" name="CalendarType" value="3" type="radio"><b>Release</b>(False) <br>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您不应该将此样式应用于收音机,而应应用于它们所在的容器,在这种情况下,您可以添加一个 div:
You shouldn't apply this style to the radios but to the container they are on, in that case you can add a div:
尝试使用以下 CSS 样式。
Try with the following CSS style.
您应该检查它们周围的容器是否对齐。
You should check the alignment of the container that surrounds them.
您尝试将仅适用于块级元素(如
div
)的 CSS 属性添加到内联元素(input
)。这是行不通的;您需要创建一个块级元素(我选择使用label
并使用 CSS 使其成为块级元素,但这只是为了语义)并使用它来包含每个标签。尝试使用
.radioLeft
类将每个标签包装在label
中,从输入中删除该类,然后添加以下 CSS:例如,
You try to add a CSS property that only applies to block-level elements (like
div
) to an inline element (input
). This won't work; you need to create a block-level element (I chose to uselabel
and make it block-level using CSS, but that's just for semantics) and use it to contain each label.Try wrapping each in a
label
with class.radioLeft
, remove that class from the inputs, and then add this CSS:For example,