html - 构建两列 html 表单的最佳方式?

标签 html css forms

对齐以下内容的最佳方式是什么?

我想要左边的 .inputTitle 和右边的 inputInput,两者之间都有错误。

CSS:

.crud_form{
    width:430px;
    margin:10px solid;
    font-family:Verdana, Geneva, sans-serif;
    background:orange;
}
.inputTitle{
    float:left;
    clear:left;
    margin:11px 10px 10px 0;
    width:95px;
    background:green;
}
.inputRequired{
    float:left;
    margin:5px;
    width:113px;
    background:blue;
}
.inputError{
    float:left;
    margin:10px;
    background:red;
}

.crud_form select textarea{
    float:left;
    clear:both;
}

HTML:

<form action="#" method="post" accept-charset="utf-8" class="crud_form" enctype="multipart/form-data">
<span class="inputTitle">First Name</span><span class="inputInput"><input type="text" name="first_name" value="" id="first_name"  /></span><span class="inputError"></span>

<span class="inputTitle">Last Name</span><span class="inputInput"><input type="text" name="last_name" value="" id="last_name"  /></span><span class="inputError"></span>

<span class="inputTitle">Address</span><span class="inputInput"><textarea name="address" cols="40" rows="10" id="address" ></textarea></span><span class="inputError"></span>

<span class="inputTitle">Phone</span><span class="inputInput"><input type="text" name="phone" value="" id="phone"  /></span><span class="inputError"></span>

<span class="inputTitle">Item</span><span class="inputInput"><select name="item" id="item">
<option value="Caps cost $15"></option>
<option value="Mugs cost $20"></option>
<option value="Childrens T-shirts, sizes 0 to 6">$10</option>
<option value="Ladies (no photo) cost $20"></option>
<option value="Men cost $20"></option>
</select></span>

<span class="inputError"></span>
<span class="inputTitle">Comments</span><span class="inputInput"><textarea name="comments" cols="40" rows="10" id="comments" ></textarea></span><span class="inputError"></span>

<input type="submit" value="Save" />

</form>

最佳答案

不知道为什么大家都在用divspanli等,很简单,看在下面的示例中:

label {
  width: 150px;
  padding-right: 20px;
  display: inline-block;
}
<p>
  <label for="IDofInput">text goes here</label>
  <input type="text" id="IDofInput">
</p>
<p>
  <label for="IDofInput">text goes here</label>
  <input type="text" id="IDofInput">
</p>
<p>
  <label for="IDofInput">text goes here</label>
  <input type="text" id="IDofInput">
</p>

关于html - 构建两列 html 表单的最佳方式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9728162/

相关文章:

html - html 电子邮件的段落格式

html - 将线性梯度语法转换为 -webkit-gradient 语法

javascript - bing map 巴林的过境路线

html - 使单元格宽度适合内容

javascript - 自动滚动到每个 div 或元素

css - 搜索引擎是否处理文本缩进 :-9999em or negative margin as SEO cheat?

css - Bootstrap : search visible when navbar collapsed

php - 注册页面上的操作 ="???"应该是什么?

提交前的 jQuery 表单发布

mysql - Cakephp 从另一个 View 中检索 id