对齐以下内容的最佳方式是什么?
我想要左边的 .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>
最佳答案
不知道为什么大家都在用div
、span
和li
等,很简单,看在下面的示例中:
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/