如何对齐多个表单元素?

Hum*_*art 6 html css web

我对设计一无所知,我试图让一个简单的HTML表单看起来像这样: .

基本上,它是一个包含三个输入字段和一个提交按钮的表单.

关于输入字段,有两个在顶部,一个在下面.我希望它们彼此完全中心对齐,第二个要拉伸到与上面相同的宽度.

关于提交按钮,我希望它与输入字段在水平和垂直方向上完全中心对齐,但是在这些按钮的右侧.

我并不担心它不是完全跨浏览器.

感谢您的任何指示!

编辑:我更喜欢它是用CSS完成而不是基于表格.(我听说基于表格的只是简单的邪恶.)

Hri*_*sto 6

用纯CSS做这样的事情怎么样?顺便说一下......你知道输入字段和搜索按钮的具体尺寸吗?如果我知道一些尺寸,我可能会做一点清洁工.无论如何,看看演示......

http://jsfiddle.net/zxSFp/1/

HTML

<div id="wrap">
    <div id="fields">
        <input type="text" id="left" />
        <input type="text" id="right" />
        <div class="clear"></div>
        <input type="text" id="bottom" />
    </div>
    <input type="button" value="Search" id="search-button" />
</div>
Run Code Online (Sandbox Code Playgroud)

CSS

#wrap {
    min-width: 375px;
    position: relative;
}
#fields {
    float: left;
    position: relative;
}
#left {
    height: 15px;
    width: 150px;
    float: left;
    position: relative;
}
#right {
    height: 15px;
    width: 150px;
    margin-left: 5px;
    float: left;
    position: relative;
}
#bottom {
    height: 15px;
    width:309px;
    margin-top: 5px;
    position: relative;
}
#search-button {
    position: relative;
    left: 15px;
    top: 12px;
}
.clear {
    clear: both;
}
Run Code Online (Sandbox Code Playgroud)

我希望这有帮助.


Tod*_*odd 5

你可以用一张桌子。:) 这是为你准备好的代码:

<table>
  <tbody>
    <tr>
      <td><input type="text" /></td>
      <td><input type="text" /></td>
      <td rowspan="2" style="vertical-align:middle;"><input type="submit" /></td>
    </tr>
    <tr>
      <td colspan="2"><input style="width:100%" type="text" /></td>
    </tr>
  </tbody>
</table>
Run Code Online (Sandbox Code Playgroud)

  • 至少对我来说,桌子不是最好的选择。关于它的一些链接:http://webdesign.about.com/od/layout/a/aa111102a.htm http://phrogz.net/css/WhyTablesAreBadForLayout.html (2认同)