简体   繁体   English

形式元素底部的神秘白色空间

[英]Mystery white space at the bottom of form element

When a form is put inside a div, there's always extra space at the bottom of the form for some reason. 当表单放在div中时,由于某种原因,表单底部总会有额外的空间。 How do we get rid of that space? 我们如何摆脱那个空间?

In the code snippets from stack overflow, it doesn't actually show the space, but anywhere else, it does. 在堆栈溢出的代码片段中,它实际上并不显示空间,但在其他任何地方,它都会显示空间。 The code below is all there is. 下面的代码就是全部。

 div { border: 1px solid blue; } form { border: 1px solid red; } 
 <div> <form> Form </form> </div> 

You can refer to web developer tools (F12), and you'll see that a form element comes with a margin-bottom: 1em , as defined in the browser's default stylesheet : 您可以参考Web开发人员工具(F12),您将看到form元素带有margin-bottom: 1em ,如浏览器的默认样式表中所定义:

在此输入图像描述

You can override that by defining your own margin rule: 您可以通过定义自己的保证金规则来覆盖它:

form { margin-bottom: 0; }

You have a margin-bottom: 16px . 你有一个margin-bottom: 16px Remove it and it will solve your problem. 删除它,它将解决您的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM