Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I can't remove the margin between two input fields

Tags:

html

css

I'm trying to remove the margin between the search bar and the "Go!" button at the top of this page: http://beta.linksku.com/

I've tried removing all styles and adding margin:0;padding:0;border:none;, but there is still a margin between the two elements. I cannot replicate this problem on JSFiddle, but it occurs in all browsers on my website.

like image 487
Leo Jiang Avatar asked Mar 23 '12 00:03

Leo Jiang


People also ask

How can I remove space between two input fields in HTML?

Approach 1: We can remove space between any two tags by simply using margin-bottom property. The margin-bottom property sets the bottom margin of an element.

How do I remove space between label and textbox?

If you have no margin or padding applied and you still have this space, you could either use display: flex on the parent or display: block/inline-block on the label to get rid of these. Both label and input are display: inline , per default, so margin and padding bottom or top should not affect them.

How do I reduce the space between two text boxes in CSS?

Set margin-top property to set space between two text boxes.


2 Answers

The space you're seeing is the default padding applied to inline elements. Simplest hack? Set font-size: 0 on the form, then reset the actual font-size on the input and button.

Magic.

form {
    font-size: 0;
}

form input {
    font-size: 12px;

Why does this occur? The browser interprets the whitespace between the inputs as a textual space, and renders accordingly. You can also smush all your elements together on one line, but that's ugly code soup.

like image 67
benesch Avatar answered Sep 19 '22 12:09

benesch


This is how elements function as inline-block.

Normally when you use inline-block elements, you often use them inside a paragraph, so the space between the letters must be consistent. inline-block elements apply to this rule too.

If you want to remove the space completely, you can float the elements.

float: left;

You can also remove the whitespace from your template document. Like so:

<input type="text" name="s" tabindex="2" /><input type="submit" value="Go!" class="btn" />
like image 44
martinjlowm Avatar answered Sep 17 '22 12:09

martinjlowm