html - Nowrap/不要在输入后换行

标签 html css

如果我有几个输入( radio 或选项)后跟它们的标签,都在同一行。我是如何做到的,这样它就不会在 radio 后断线,而是在标签后如果需要断线。

<input type="radio" id="i1"/><label for="i1">First radio</label>
<input type="radio" id="i2"/><label for="i2">Second radio</label>
<input type="radio" id="i3"/><label for="i3">Third radio</label>

我可以考虑用 nowrapinputlabel 包装在一个 span 中,但想知道是否有另一种方式。

最佳答案

这应该可以解决问题:

#MyDiv {width: 250px;}
<div id="MyDiv">
    <nobr><input type="radio" id="i1"/><label for="i1">First radio</label></nobr>
    <nobr><input type="radio" id="i2"/><label for="i2">Second radio</label></nobr>
    <nobr><input type="radio" id="i3"/><label for="i3">Third radio</label></nobr>
</div>

<nobr>标签将确保按钮和标签之间不会发生中断。

CSS方式也是可以的,用另一个<span>包裹起来并使用 white-space: nowrap;应该可以正常工作。

关于html - Nowrap/不要在输入后换行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7510612/

相关文章:

html - 在移动设备上从右上到下引导网格

php - 如何通过输入从DB中获取某一行的id?

html - 跨度 css 无法正常工作

css - 使用框架样式对 React 组件进行样式化

javascript - 在 Django html 模板中包含 html、css、js 小部件

javascript - 使用 jQuery 显示/切换每个元素在任何特定时刻只在屏幕上显示一个

html - 这可能与 CSS 3

javascript - 清除选项卡形式的某些文本字段

html - 如何使用 Jekyll 按自定义 YAML 前端变量对帖子进行排序?

html - 使容器在包裹时收缩以适合子元素