将单选按钮彼此左对齐的最佳方法是什么?

发布于 2024-10-08 05:04:21 字数 642 浏览 0 评论 0原文

我有一堆单选按钮,

<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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

蓝咒 2024-10-15 05:04:21

您不应该将此样式应用于收音机,而应应用于它们所在的容器,在这种情况下,您可以添加一个 div:

<div class="radioLeft">
  <input checked="checked" name="CalendarType" value="1" type="radio"><b>Person </b>(False) <br>
   <input checked="checked" name="CalendarType" value="2" type="radio"><b>Event </b>(False) <br>
   <input checked="checked"  name="CalendarType" value="3" type="radio"><b>Release</b>(False) <br>
</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:

<div class="radioLeft">
  <input checked="checked" name="CalendarType" value="1" type="radio"><b>Person </b>(False) <br>
   <input checked="checked" name="CalendarType" value="2" type="radio"><b>Event </b>(False) <br>
   <input checked="checked"  name="CalendarType" value="3" type="radio"><b>Release</b>(False) <br>
</div>
你是年少的欢喜 2024-10-15 05:04:21

尝试使用以下 CSS 样式。

.radioLeft input{
    text-align: left;
    display:inline;
}

Try with the following CSS style.

.radioLeft input{
    text-align: left;
    display:inline;
}
冰葑 2024-10-15 05:04:21

您应该检查它们周围的容器是否对齐。

You should check the alignment of the container that surrounds them.

鱼忆七猫命九 2024-10-15 05:04:21

您尝试将仅适用于块级元素(如 div)的 CSS 属性添加到内联元素(input)。这是行不通的;您需要创建一个块级元素(我选择使用 label 并使用 CSS 使其成为块级元素,但这只是为了语义)并使用它来包含每个标签。

尝试使用 .radioLeft 类将每个标签包装在 label 中,从输入中删除该类,然后添加以下 CSS:

.radioLeft {
  display: block;
  text-align: left;
}

例如,

<label class="radioLeft"><input type="radio"><b>Person</b>(False)</label>

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 use label 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:

.radioLeft {
  display: block;
  text-align: left;
}

For example,

<label class="radioLeft"><input type="radio"><b>Person</b>(False)</label>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文