清除输入而不添加 Float

发布于 2024-12-29 20:45:23 字数 513 浏览 2 评论 0原文

如果不添加浮动,提交按钮似乎无法正确清除。有人可以帮我解决这个问题吗(没有双关语)。

http://jsfiddle.net/qb5TH/

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).

http://jsfiddle.net/qb5TH/

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

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

发布评论

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

评论(2

自找没趣 2025-01-05 20:45:23

我可能不太清楚你的意图,但如果你想让你的按钮到它自己的行,你可以强制它使用 display: 块,它会转到下一行。

这是 CSS:

.left {float:left;}
.clear {clear:both;}
input[type=submit] {display: block;}

**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:

.left {float:left;}
.clear {clear:both;}
input[type=submit] {display: block;}

**jsfiddle sample here

凡间太子 2025-01-05 20:45:23

提交按钮没有移动到下一行的原因是 input 是一个 inline 元素。根据 CSS 规范clear 在内联元素上被忽略(相关引用:“适用于:块级元素”)。在提交按钮上设置 float 有效,因为 设置 float 在大多数情况下还会设置 display: block。您可以通过直接在要清除的提交按钮上设置 display: block 来达到相同的效果:

.left {float:left}
.clear {clear:both}
input[type=submit].clear {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"). Setting float on the submit button works because setting float in most cases also sets display: block. You can achieve the same effect by directly setting display: block on the submit buttons that you want to clear:

.left {float:left}
.clear {clear:both}
input[type=submit].clear {display:block}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文