且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

垂直对齐输入

更新时间:2022-12-15 11:01:52

您可以使用 CSS表格布局 。父元素充当表行,子元素充当表单元格。

You can make use of CSS table layout. The parent element acts as a table row and the child elements as table cells.

.input-container {
  display: table-row;
}
.input-container * {
  display: table-cell;
  margin-left: 5px;
}

<fieldset>
  <legend>Team1</legend>
  <div class="input-container">
    <label for="player1">Player1</label>
    <input type="number" name="player1">
  </div>
  <div class="input-container">
    <label for="player2">Player2345</label>
    <input type="number" name="player2">
  </div>
</fieldset>