清除输入而不添加 Float
如果不添加浮动,提交按钮似乎无法正确清除。有人可以帮我解决这个问题吗(没有双关语)。
CSS:
.left {float:left}
.clear {clear:both}
形式:
<form>
<label class="left">Label</label>
<input type="text" class="left">
<label class="clear left">Label</label>
<input type="text" class="left">
<input type="submit" class="clear">
</form>
Submit buttons don't seem to clear properly without also adding float. Can someone clear this up for me (no pun intended).
CSS:
.left {float:left}
.clear {clear:both}
Form:
<form>
<label class="left">Label</label>
<input type="text" class="left">
<label class="clear left">Label</label>
<input type="text" class="left">
<input type="submit" class="clear">
</form>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我可能不太清楚你的意图,但如果你想让你的按钮到它自己的行,你可以强制它使用 display: 块,它会转到下一行。
这是 CSS:
**jsfiddle 示例
I might not be exactly clear on your intent but if you want to get your button to it's own line you can force it to use display: block and it will go to the next line.
Here's the CSS:
**jsfiddle sample here
提交按钮没有移动到下一行的原因是
input
是一个 inline 元素。根据 CSS 规范,clear 在内联元素上被忽略(相关引用:“适用于:块级元素”)。在提交按钮上设置
float
有效,因为 设置float
在大多数情况下还会设置display: block
。您可以通过直接在要清除的提交按钮上设置display: block
来达到相同的效果:The reason why the submit button doesn't move to the next line is because
input
is an inline element. According to the CSS spec,clear
is ignored on inline elements (relevant quote: "Applies to: block-level elements"). Settingfloat
on the submit button works because settingfloat
in most cases also setsdisplay: block
. You can achieve the same effect by directly settingdisplay: block
on the submit buttons that you want to clear: