I can't remove the margin between two input fields

前端 未结 5 684
忘了有多久
忘了有多久 2021-01-02 02:22

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

相关标签:
5条回答
  • 2021-01-02 02:27

    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" />
    
    0 讨论(0)
  • 2021-01-02 02:27

    That whitespace is relative to your font-size. You can remove it by adding font-size:0 on the container of your inputs, in this case a form, like so:

    form {
        font-size: 0;
    }
    
    0 讨论(0)
  • 2021-01-02 02:38

    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.

    0 讨论(0)
  • 2021-01-02 02:41

    One way is to remove space, but if you're not willing to have an unreadable one-line mess, you can use HTML comment:

    <form id="search" method="get" action="http://beta.linksku.com/">
          <input type="text" name="s" tabindex="2"><!--
      !--><input type="submit" value="Go!" class="btn">
    </form>
    
    0 讨论(0)
  • 2021-01-02 02:50

    Using chrome on the Mac, I can get rid of the space if I edit the form node as HTML in the Developer tools, and remove the space between the two closing tags so:

    <form id="search" method="get" action="http://beta.linksku.com/">
            <input type="text" name="s" tabindex="2">
            <input type="submit" value="Go!" class="btn">
          </form>
    

    becomes:

    <form id="search" method="get" action="http://beta.linksku.com/">
            <input type="text" name="s" tabindex="2"><input type="submit" value="Go!" class="btn">
          </form>
    
    0 讨论(0)
提交回复
热议问题