spacing between form fields

2020-03-06 17:57发布

I have an HTML form element:

<form action="doit" id="doit" method="post">
Name <br/>
<input id="name" name="name" type="text" /> <br/>
Phone number <br/>
<input id="phone" name="phone" type="text" /> <br/>
Year <br/>
<input id="year" name="year" type="text" /> <br/>
</form>

I would like there to be a little more space between the fields, for example, between the lines

<input id="name" name="name" type="text" /> <br/> and Phone number <br/>,

and also between

<input id="phone" name="phone" type="text" /> <br/> and Year <br/>.

How can I do it?

标签: html css forms
4条回答
爷、活的狠高调
2楼-- · 2020-03-06 18:29

I would wrap your rows in labels

<form action="doit" id="doit" method="post">
    <label>
        Name
        <input id="name" name="name" type="text" />
    </label>
    <label>
        Phone number
        <input id="phone" name="phone" type="text" />
    </label>
    <label>
        Year
        <input id="year" name="year" type="text" />
    </label>
</form>

And use

label, input {
    display: block;
}

label {
    margin-bottom: 20px;
}

Don't use brs for spacing!

Demo: http://jsfiddle.net/D8W2Q/

查看更多
Fickle 薄情
3楼-- · 2020-03-06 18:31
  <form>     
            <div class="form-group">
                <label for="nameLabel">Name</label>
                <input id="name" name="name" class="form-control" type="text" /> 
            </div>
            <div class="form-group">
                <label for="PhoneLabel">Phone</label>
                <input id="phone" name="phone" class="form-control" type="text" /> 
            </div>
            <div class="form-group">
                <label for="yearLabel">Year</label>
                <input id="year" name="year" class="form-control" type="text" />
            </div>
        </form>
查看更多
闹够了就滚
4楼-- · 2020-03-06 18:46

A simple &nbsp; between input fields would do the job easily...

查看更多
一夜七次
5楼-- · 2020-03-06 18:53

In your CSS file:

input { margin-bottom: 10px; }
查看更多
登录 后发表回答