Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Each form element <label>+<input> on new line without <div>

Tags:

html

css

forms

Is there a solution to move each form element on a new line without closing these elements on divs?

I mean:

<label for="one">One:</label>  <input type="text" id="one">
<label for="two">Two:</label>  <select id="two">
                                  <option value="a">a</option>
                                  <option value="b">b</option>
                               </select>
...

To display:

One:   [.......]
Two:   [a    \/]
and so on...

If I put on CSS:

input, select, label {
   display:block;
}

then labels are not on the same line as the form fields.

Is the only solution:

<div><label for="one">One:</label>  <input type="text" id="one"></div>
...
like image 477
Perocat Avatar asked Dec 30 '13 01:12

Perocat


People also ask

How do you put labels and input on different lines?

There are two ways to pair a label and an input. One is by wrapping the input in a label (implicit), and the other is by adding a for attribute to the label and an id to the input (explicit).

How do you put an input element on the same line as its label?

Using table cell attribute in display property: Make a label inside a div and give the display property. To make the input element and span as equally placed use table-cell attribute in those tags. This attribute makes the element behaves a td element.

How do you enter a new line in HTML?

To add a line break to your HTML code, you use the <br> tag. The <br> tag does not have an end tag. You can also add additional lines between paragraphs by using the <br> tags. Each <br> tag you enter creates another blank line.

How do you put an input on the same line in HTML?

Use display:inline-block insted of float .


1 Answers

Another way to do it is like this

<label><span>One:</span><input type="text" id="one"></label>

and the css

label {
display:block;
position:relative;
padding-left:120px; /* adjust if necessary */
}
label > span {
position:absolute;
left:0;
}
like image 155
Michael Avatar answered Oct 13 '22 20:10

Michael