Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

displaying html form inputs horizontally

i am trying to recreate the login form shown on tinypic's main page.

login

in html, i have the 3 elemnts like this:

E-Mail:
<input type="text" name="id" maxlength="30" value="" />
Password:
<input type="text" name="pw" maxlength="30" value="" />

<input type="submit" name="submit" value="Login" />

i have tried putting them into separate divs, using float:left with a unique class in css but the code is really messy unreasonably long. so essentially, i wanted to know if there was a simple way to achieve this layout with html and css.

thanks for the time!

like image 639
Kevin Jung Avatar asked May 11 '11 21:05

Kevin Jung


2 Answers

This CSS should work, though I haven't tested:

input { display: inline; }
like image 125
Brian Driscoll Avatar answered Oct 02 '22 19:10

Brian Driscoll


Here is my solution: ( http://jsfiddle.net/HcppN/ )

HTML:

<label>E-Mail:</label>
<input type="text" name="id" maxlength="30" value="" />
<label>Password:</label> 
<input type="text" name="pw" maxlength="30" value="" />

<input type="submit" name="submit" value="Login" />

CSS:

input, label {
    float:left;
    margin:5px;
}

I also recommend you to encapsulate the labels in <label> tags. You can even use the for="inputId" attribute, so that clicking on the label brings the input into focus.

like image 25
Iulius Curt Avatar answered Oct 02 '22 19:10

Iulius Curt