html - 表单字段之间的间距

标签 html css forms

我有一个 HTML 表单元素:

<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>

我希望字段之间有更多的空间,例如,行之间

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

还有在

之间

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

我该怎么做?

最佳答案

我会用标签包裹你的行

<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>

并使用

label, input {
    display: block;
}

label {
    margin-bottom: 20px;
}

不要使用 br 作为间距!

演示:http://jsfiddle.net/D8W2Q/

关于html - 表单字段之间的间距,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16379187/

相关文章:

javascript - 如何只在 div 中按下按键?

html - 每个 HTML 页面上的相同元素?

html - 使用@fontface,如何将不同的样式应用于不同的字体系列?

javascript - 自定义剪切,如 HTML5 和 CSS 中的背景

javascript - 全屏部分由 translateX 更改

javascript - 找不到动态添加的表单元素 ID

html - span 比父 div 小,为什么?

javascript - 如何禁用 <a> 标签的标签

html - 表单:您的 CSS 是否适合您的标记,反之亦然?

javascript - 无法在表单上返回 false