2015-07-07 11:25:16 +08:00
|
|
|
# 水平排列的表单
|
2015-06-15 20:24:01 +08:00
|
|
|
|
2015-07-07 23:45:46 +08:00
|
|
|
- order: 0
|
2015-06-15 20:24:01 +08:00
|
|
|
|
2015-06-16 09:54:10 +08:00
|
|
|
为 `<form>` 标签添加 `.ant-form-horizontal` 类(这让 `.ant-form-item` 表现为栅格系统中的 `row`),并结合使用我们提供的 [栅格系统](http://ant.design/components/layout/),可以实现 label 标签和表单控件的水平排列。
|
2015-06-15 20:24:01 +08:00
|
|
|
|
2015-08-03 13:34:40 +08:00
|
|
|
如需将一行静态文本和 `<label>` 标签置于同一行,则只需为标签添加 `.ant-form-text` 类即可。
|
2015-07-07 11:25:16 +08:00
|
|
|
|
2015-07-07 23:45:46 +08:00
|
|
|
为 `label` 标签添加 `required` 属性,表示该项必选。
|
2015-07-07 11:25:16 +08:00
|
|
|
|
2015-08-03 13:34:40 +08:00
|
|
|
**注意**:在我们的设计里,表单域(`.ant-form-item`) 为静态文本、`checkbox`、`radio`以及`input[type="file"]`的,其高度不同于一般的表单域,需要在 `.ant-form-item` 类后再加上 **`.ant-form-item-compact`**。
|
2015-07-17 15:12:48 +08:00
|
|
|
|
2015-06-15 20:24:01 +08:00
|
|
|
---
|
|
|
|
|
2015-07-20 20:35:48 +08:00
|
|
|
````jsx
|
|
|
|
var Checkbox = antd.Checkbox;
|
|
|
|
var Radio = antd.Radio;
|
|
|
|
var RadioGroup = antd.RadioGroup;
|
|
|
|
|
|
|
|
React.render(
|
|
|
|
<form className="ant-form-horizontal">
|
|
|
|
<div className="ant-form-item ant-form-item-compact">
|
|
|
|
<label for="userName" className="col-6" required>用户名:</label>
|
|
|
|
<div className="col-6">
|
|
|
|
<p className="ant-form-text">大眼萌 minion</p>
|
2015-07-07 11:25:16 +08:00
|
|
|
</div>
|
2015-06-15 20:24:01 +08:00
|
|
|
</div>
|
2015-07-20 20:35:48 +08:00
|
|
|
<div className="ant-form-item">
|
|
|
|
<label for="password" className="col-6" required>密码:</label>
|
|
|
|
<div className="col-14">
|
|
|
|
<input className="ant-input" type="password" id="password" placeholder="请输入密码"/>
|
|
|
|
</div>
|
2015-06-15 20:24:01 +08:00
|
|
|
</div>
|
2015-07-20 20:35:48 +08:00
|
|
|
<div className="ant-form-item ant-form-item-compact">
|
|
|
|
<label className="col-6" required>您的性别:</label>
|
|
|
|
<div className="col-14">
|
2015-07-21 16:26:53 +08:00
|
|
|
<RadioGroup value="male">
|
|
|
|
<Radio value="male">男的</Radio>
|
2015-07-20 20:35:48 +08:00
|
|
|
<Radio value="female">女的</Radio>
|
|
|
|
</RadioGroup>
|
2015-07-07 11:25:16 +08:00
|
|
|
</div>
|
2015-07-16 14:18:03 +08:00
|
|
|
</div>
|
2015-07-20 20:35:48 +08:00
|
|
|
<div className="ant-form-item">
|
|
|
|
<label for="password" className="col-6" required>备注:</label>
|
|
|
|
<div className="col-14">
|
|
|
|
<textarea className="ant-input" placeholder="随便写"></textarea>
|
2015-07-21 14:55:22 +08:00
|
|
|
<p className="ant-form-explain">随便写点什么</p>
|
2015-07-07 11:25:16 +08:00
|
|
|
</div>
|
|
|
|
</div>
|
2015-07-20 20:35:48 +08:00
|
|
|
<div className="ant-form-item ant-form-item-compact">
|
|
|
|
<div className="col-14 col-offset-6">
|
2015-06-15 20:24:01 +08:00
|
|
|
<label>
|
2015-07-20 20:35:48 +08:00
|
|
|
<Checkbox /> 同意
|
2015-06-15 20:24:01 +08:00
|
|
|
</label>
|
|
|
|
</div>
|
|
|
|
</div>
|
2015-07-20 20:35:48 +08:00
|
|
|
<div className="row">
|
|
|
|
<div className="col-16 col-offset-6">
|
|
|
|
<input type="submit" className="ant-btn ant-btn-primary" value="确 定" />
|
2015-07-07 11:25:16 +08:00
|
|
|
</div>
|
|
|
|
</div>
|
2015-06-15 20:24:01 +08:00
|
|
|
</form>
|
2015-07-20 20:35:48 +08:00
|
|
|
, document.getElementById('components-form-demo-horizontal-form'));
|
2015-06-15 20:24:01 +08:00
|
|
|
````
|