displaying html form inputs horizontally

2019-02-16 16:14发布

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!

3条回答
爱情/是我丢掉的垃圾
2楼-- · 2019-02-16 16:52

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

input { display: inline; }
查看更多
我欲成王,谁敢阻挡
3楼-- · 2019-02-16 16:52

Just add display:inline to your input elements, as shown here

查看更多
男人必须洒脱
4楼-- · 2019-02-16 16:54

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.

查看更多
登录 后发表回答