输入文本框和标签 - 如何使它们相等?

时间:2011-10-31 17:56:14

标签: html css

所以我试图输入文本框以及它们的描述,我希望每个文本框最终具有相同的长度。例如,我会有一个看起来像这样的文本框:

Username: [             ]

但是,假设我还有一个输入文本框,上面写着“OS:”

我希望它是这样的:

Username: [             ]
OS:       [             ]

我希望这对于表格内的每个输入字段都是正确的(或者不在表格中?我不确定)

我该怎么做?

编辑:

我有多个字段,所有字段我想要的长度相同,即:

Username:     [             ]      Machine Name: [             ]
OS:           [             ]      Model:        [             ]

这是我的代码:

<form action="addrecord.psp" method="get">
<table>
<tr><td>Username: <input type="text" name="uname" size="12"/></td>
<td>Machine Name:<input type="text" name="mname" size="8" /></td>
<td>Make: <input type=text" name="make" size="8" /></td>
<td>Model: <input type="text" name="model" size="8"/></td>
<td>Service Tag: <input type="text" name="service" size="8"/></td></tr>
<tr><td>Processor: <input type="text" name="processor" size="12"/></td>
<td>Processor Speed: <input type="text" name="speed" size="4"/></td>
<td>Amount of RAM: <input type="text" name="ram" size="3"/></td>
<td>Type of RAM: <input type="text" name="ram2" size="4"/></td>
<td>RAM Speed: <input type="text" name="rspeed" size="4"/></td></tr>
<td>Graphics Card: <input type="text" name=graphics" size="8"/></td>
<td>Wired Mac Add: <input type="text" name="wired" size="17"/></td>
<td>Wireless Mac Add: <input type="text" name="wireless" size="17"/></td></tr>
<tr><td>OS: <input type="text" name="os" size="12"/></td>
<td>Deploy Date: <input type="text" name="deploy" size="12"/></td>
<td>Last Check-up: <input type="text" name="checkup" size="12"/></td>
<td><input type="submit" value="Submit" /></td></tr>
</table>
</form>

我不相信我的新表单,如果字段集正确提交,我会收到以下回调:

追踪(最近一次呼叫最后一次):

HandlerDispatch中的

文件“/usr/lib/python2.7/dist-packages/mod_python/importer.py”,第1537行     default = default_handler,arg = req,silent = hlist.silent)

文件“/usr/lib/python2.7/dist-packages/mod_python/importer.py”,第1229行,在_process_target中     result = _execute_target(config,req,object,arg)

文件“/usr/lib/python2.7/dist-packages/mod_python/importer.py”,第1128行,在_execute_target中     result = object(arg)

文件“/usr/lib/python2.7/dist-packages/mod_python/psp.py”,第337行,处理程序     p.run()

文件“/usr/lib/python2.7/dist-packages/mod_python/psp.py”,第243行,在运行中     global_scope中的exec代码

文件“/var/www/inventory/addrecord.psp”,第34行,in     VALUES(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s) “”,(用户名,mname,品牌,型号,服务,处理器,速度,内存,ram2,速度,图形,有线,无线,操作系统,部署,检查))

文件“/usr/lib/pymodules/python2.7/MySQLdb/cursors.py”,第174行,执行     self.errorhandler(self,exc,value)

文件“/usr/lib/pymodules/python2.7/MySQLdb/connections.py”,第36行,在defaulterrorhandler中     提出错误类,错误值

OperationalError:(1048,“列'用户'不能为空”)

1 个答案:

答案 0 :(得分:2)

更有效的方法:

<style>

fieldset { 
    overflow: hidden; 
    margin-bottom: 5px;
    display: inline-block;
    width: 270px;
}

label { float: left; width: 120px; }

input { width: 120px; }

</style>

<fieldset>
  <label for="username">Username:</label>
  <input type="text" id="username" />
</fieldset>
<fieldset>
  <label for="mname">Machine Name:</label>
  <input type="text" id="mname" />
</fieldset>
<fieldset>
  <label for="os">OS:</label>
  <input type="text" id="os" />
</fieldset>
<fieldset>
  <label for="model">Model:</label>
  <input type="text" id="model" />
</fieldset>

这样,您还可以将焦点光标对准字段,然后单击其标签。

示例:http://jsfiddle.net/6SVp7/1/

相关问题