Skip to content
Home » Web » CSS » Same Line With <Select> Box

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:

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:

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. Required fields are marked *