Skip to content

2 Ways To Make Text In The Same Line With <Select> Box

You might want the leading text in the same line with <select> or <input> object, but cannot make it, why? Let's see the following example:

Please Select Fruit:
<form>
  <select name='fruit'>
    <option>Apple</option><option>Banana</option>
  </select>
</form>

It will output like this:

Please Select Fruit:

It results two separate lines in this example. Here I introduce two ways to make them in only one line:

1. Enclose the leading text by <span> with float to left:

<span style='float:left;'>Please Select Fruit:</span>
<form>
  <select name='fruit'>
    <option>Apple</option><option>Banana</option>
  </select>
</form>

It will output like this:

Please Select Fruit:

2. Move the text inside the <form>

<form>
  Please Select Fruit:
  <select name='fruit'>
    <option>Apple</option><option>Banana</option>
  </select>
</form>

It will output like this:

Please Select Fruit:

In fact, I like the second way, it's simple and fast, and the most important is they are aligned with each other vertically.

Leave a Reply

Your email address will not be published.