css - 使用 CSS 对齐表单域

标签 css forms drupal alignment inline

我在 Dupal 7 中有一个高级搜索表单(单击“高级搜索”)- http://www.ibuild.ph/mtf-rdp-minimal/search/node和联系表格 - http://www.ibuild.ph/mtf-rdp-minimal/contact .搜索字段是内联的,而联系字段位于标签下方。

有没有办法用文本标签内联定位字段并使字段彼此垂直对齐,而无需将文本标签和表单字段分开在两个 div 中?

最佳答案

使用表格

您可以通过更改 width: 100px;

来更改标签的宽度

<table style="width: 100%;">
<colgroup>
    <col style="width: 100px;">
    <col>
<colgroup>
<tr>
    <td>Name</td>
    <td><input type="text" /></td>
</tr>
  
<tr>
    <td>Address</td>
    <td><input type="text" /></td>
</tr>
  
</table>

使用最小宽度:

<div>
  <label style="display: inline-block; min-width: 100px;">Name: </label><input type="text" />  
</div>
    
<div>
  <label style="display: inline-block; min-width: 100px;">Address: </label><input type="text" />  
</div>

关于css - 使用 CSS 对齐表单域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28790219/

相关文章:

html - div 之间的空间从何而来?

javascript - 在 JavaScript 函数中更改 HTML 按钮的样式

c# - 将字符串数组的元素链接到十进制值

php - 用文本替换空表单域

drupal 6 cck字段: is there a easy way to duplicate cck field?

mysql - 在 github.io 中运行 drupal 站点

javascript - 获取具有相同类的元素的 id

html - css 最大高度在 div 中不起作用

javascript - 使用 javascript 验证 html 表单

php - 设置 PHP 5.2 服务器