强制标签与它们标记的输入内联流动
我需要标签与它们标记的输入字段保持在同一行。我希望这些元素在窗口大小调整时像平常一样流动,我只想将标签粘贴到它们正在标记的输入的左侧。我该怎么做呢?有什么想法吗?
<label for="id1">label1:</label>
<input type="text" id="id1"/>
<label for="id2">label2:</label>
<input type="text" id="id2"/>
回答:Josiah Ruddell 的答案是正确的,使用 span 而不是 div 给了我正确的行为。谢谢!
<span style="white-space:nowrap">
<label for="id1">label1:</label>
<input type="text" id="id1"/>
</span>
<span style="white-space:nowrap">
<label for="id2">label2:</label>
<input type="text" id="id2"/>
</span>
I need the label to stay on the same line as the input field they are labeling. I want these elements to flow like they normally would when the window resizes, i just want the label to stick to the left of the input they are labeling. How would I do that? Any ideas?
<label for="id1">label1:</label>
<input type="text" id="id1"/>
<label for="id2">label2:</label>
<input type="text" id="id2"/>
ANSWERED: Josiah Ruddell's answer was on the right path, using a span instead of div gave me the correct behavior. Thanks!
<span style="white-space:nowrap">
<label for="id1">label1:</label>
<input type="text" id="id1"/>
</span>
<span style="white-space:nowrap">
<label for="id2">label2:</label>
<input type="text" id="id2"/>
</span>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
使用 nowrap 将它们都放在
div
中。put them both inside a
div
with nowrap.将
input
放在标签中,并放弃for
属性但是,当然,如果您想设置文本样式怎么办?只需使用
span
。Put the
input
in the label, and ditch thefor
attributeBut of course, what if you want to style the text? Just use a
span
.将您的输入包裹在 label 标签内
Wrap your inputs within the label tag
http://jsfiddle.net/jwB2Y/123/
以下 CSS 类强制标签文本流动内联并在其长度超过标签的最大长度时被剪裁。
HTML:
http://jsfiddle.net/jwB2Y/123/
The following CSS class force the label text to flow inline and get clipped if its length is more than max-length of the label.
HTML:
我所做的就是让输入不占用整行,并且能够将输入放在一个段落中,我使用了一个 span 标签并显示为 inline-block
html:
css:
What I did so that input didn't take up the whole line, and be able to place the input in a paragraph, I used a span tag and display to inline-block
html:
css:
如果您希望它们成为段落,请使用它。
和
都是段落和流内容,因此您可以作为段落元素和块元素插入。
If you want they to be paragraph, then use it.
Both
<label>
and<input>
are paragraph and flow content so you can insert as paragraph elements and as block elements.你为什么不直接使用:
Why don't You just use: