两列形式,每列中有动态行数

时间:2018-12-25 13:37:31

标签: html css flexbox

我正在尝试设计以下表格,其中将有2列。每列可以具有任意数量的表单域,例如左列只能有一个表单域,右列也只能有一个表单域,或者左列可以有两个表单域,右列可以有三个表单域,反之亦然。

我正在做的方式不会分隔两列。这是我所做的

这是我尝试使用flex

.row {
  display: flex;
}

.input-wrapper {
  flex: 1;
  padding-left: 15px;
}
<div class="row">
  <div class="input-wrapper">
    <label>Additional Space</label>
    <select>
      <option>hello</option>
    </select>
  </div>
  <div class="input-wrapper">
    <label>Size</label>
    <input type="text" placeholder="length" />
  </div>
  <div class="input-wrapper">
    <label></label>
    <input type="text" placeholder="width" />
  </div>
  <div class="input-wrapper">
    <label></label>
    <select>
      <option>hello</option>
    </select>
  </div>
</div>

<br/><br/><br/><br/><br/>


<div class="row">
  <div class="input-wrapper">
    <label>Additional Space</label>
    <select>
      <option>hello</option>
    </select>
  </div>
  <div class="input-wrapper">
    <label>Size</label>
    <input type="text" placeholder="length" />
  </div>
</div>

这是设计

enter image description here

1 个答案:

答案 0 :(得分:0)

首先,您需要将width: 100%设置为要跨越的输入类型。在您的布局中,容器已经占据了整个宽度。

您还应该在display:flex上使用input-wrapper并进行设置

flex-direction: column;
justify-content: flex-end;

为了使文本首先显示,在第二行显示输入内容。

.row {
  display: flex;
}

.input-wrapper {
  flex: 1;
  padding-left: 15px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
}


select{
  width: 100%;
}

select, input{
  border: 1px solid #e1e1e1;
  padding: 6px;
  border-radius: 3px;
}

label{
  font-size: 14px;
  color: #d1d1d1;
  margin-bottom: 4px;
}
<div class="row">
  <div class="input-wrapper">
    <label>Additional Space</label>
    <select>
      <option>hello</option>
    </select>
  </div>
  <div class="input-wrapper">
    <label>Size</label>
    <input type="text" placeholder="length" />
  </div>
  <div class="input-wrapper">
    <label></label>
    <input type="text" placeholder="width" />
  </div>
  <div class="input-wrapper">
    <label></label>
    <select>
      <option>hello</option>
    </select>
  </div>
</div>

<br/><br/><br/><br/><br/>


<div class="row">
  <div class="input-wrapper">
    <label>Additional Space</label>
    <select>
      <option>hello</option>
    </select>
  </div>
  <div class="input-wrapper">
    <label>Size</label>
    <input type="text" placeholder="length" />
  </div>
</div>

相关问题