0

Hello everybody i think this problem happen all the time and i believe it's annoying to us all but does anyone know how to remove this white space from select boxes?

<select>
  <option>
    testing
  </option>
</select>
<select>
  <option>
    testing
  </option>
</select>
Carl Binalla
  • 5,393
  • 5
  • 27
  • 46

4 Answers4

0

There are a few ways to resolve this - one solution would be to use flex-box to remove this spacing by adding the following CSS to your document:

<!-- Add this styling -->
<style>
  body {
    /* Apply flex box to parent of select elements to remove whitespace */
    display: flex;
    flex-direction: row;
  }
</style>
<select>
  <option>testing</option>
</select>
<select>
  <option>testing</option>
</select>
Dacre Denny
  • 29,664
  • 5
  • 45
  • 65
-1

HTML has some default space between some elements, if they are on 2 separate lines of code.

So let me give an example on this:

<div class="group">
  Two selects with normal markup
  <select>
    <option>Option</option>
  </select>
  <select>
    <option>Option</option>
  </select>
</div>

<div class="group">
  Two selects with comment between each
  <select>
    <option>Option</option>
  </select><!--
  --><select>
    <option>Option</option>
  </select>
</div>

<div class="group">
  Two selects with no new line between each
  <select>
    <option>Option</option>
  </select><select>
    <option>Option</option>
  </select>
</div>

As you can see in the HTML, you can either add <!-- after the end tag of the first select and --> before the opening tag of the 2nd select or you can put the opening tag of the 2nd select right after the end tag of the first one.

That way there is no spacing between them.

Tobias Glaus
  • 3,008
  • 3
  • 18
  • 37
-1

Simply comment the spaces between the two boxes. Or don’t let spaces between closing tag and next opening tag.

<select>
  <option>
    testing
  </option>
</select><!--
--><select>
  <option>
    testing
  </option>
</select><select>
  <option>
    testing
  </option>
</select>
-1

This happens because the parent tag, in your case <body> has by default display: block. This little space you see comes from the new line where you put at your second <select> tag.

There are many options in order to overcome this: Either use float: left for your <select>, or change the display property of your parent tag.

korteee
  • 2,640
  • 2
  • 18
  • 24