Mystery white space at the bottom of form element
Asked Answered
T

2

6

When a form is put inside a div, there's always extra space at the bottom of the form for some reason. 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>
Tristatristam answered 18/10, 2016 at 22:51 Comment(4)
If you can't reproduce it here than we can't help. My wild guess is that you have some margin defined somewhere in your css. You can use the developer tools to check the computed css and see where this margin/padding come fromFathomless
Or it could be part of the default styles for your browser. You may want to look into doing a CSS reset.Nonna
@ItayGal The code is all here. It's just something with stackoverflow's snippet that correct things like that, when it's not corrected anywhere else. Here's a link to the page with the problem: chatwithibot.com/testx.phpTristatristam
@ItayGal You'll be able to see from the source code that that's all there it is to the code itself.Tristatristam
L
6

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:

enter image description here

You can override that by defining your own margin rule:

form { margin-bottom: 0; }
Larkins answered 18/10, 2016 at 23:15 Comment(0)
F
0

You have a margin-bottom: 16px. Remove it and it will solve your problem.

Fathomless answered 18/10, 2016 at 23:6 Comment(2)
That must be by default. Because I didn't define it in the HTML.Tristatristam
You can do a CSS reset and define all the paddings/margins. cssreset.com/what-is-a-css-resetFathomless

© 2022 - 2024 — McMap. All rights reserved.