簡體   English   中英

如何設置 layout=&quot;horizo​​ntal&quot; 里面的幾個<Form.Item>同時保持<Form layout="vertical">在螞蟻設計中

[英]How to set the layout="horizontal" inside for few <Form.Item> while keeping <Form layout="vertical"> in ant design

我有一個<Form>有 layout="vertical" 但在這個 Form 里面我想設置一些項目有 layout="horizo​​ntal"。

我嘗試了在同一行中顯示<Form.Item> <Input.Group compact>但我也希望<Form.Item><Input/>框的標簽“TestLabel”在單行中。

           <Form
            layout="vertical"
            size="medium"
           >
                 <Input.Group compact>
                          <Form.Item label={product.productName + " : "} />
                        <Form.Item label={"TestLabel"} >
                             <Input />
                        </Form.Item>
                 </Input.Group>
          </Form>

但是“TestLabel”和輸入框垂直對齊,但我希望它水平對齊。 我正在將 React 與 Ant Design 一起使用。

我刪除了父<Form.Item>並在<Input/>中的addonBefore={"TestLabel"}中設置標簽,該標簽水平對齊標簽和<Input> 這是更新后的代碼。

      <Form
        layout="vertical"
        size="medium"
       >
             <Input.Group compact>
                 <Form.Item label={product.productName + " : "} />
                 <Input addonBefore={"TestLabel"}  style={{ width:"34%" }} />
             </Input.Group>
      </Form>

為了解決這個問題,我創建了兩個類並將它們應用在Form.ItemInput

在你的 css 中:

.classA {
  display: flex;
  flex-direction: row;
}

.classB {
  margin-left: 10px;
}

在你的html中:

<Form
  layout="vertical"
  size="medium"
>
  <Form.Item
    name='input-name'
    label='input-label'
    className='classA '
  >
    <InputNumber className='classB' />
  </Form.Item>
</Form>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM