Vertically Align Input When Using FlexBox

This question already has an answer here:

  • Flexbox: center horizontally and vertically 8 answers

  • Give the .item div display: flex; align-items: center display: flex; align-items: center since it's the parent of the input element:

    .container {
      /* Flex Properties */
      display: flex;
      flex-wrap: wrap;
      flex-direction: column;
      align-items: center;
    }
    
    .item {
      display: flex;
      align-items: center;
      background-color: orange;
    }
    
    label {
      width: 100px;
      /*display: inline-block; not necessary*/
    }
    <div class="container">
      <div class="item">
        <label>Gee my iefwaf fwats: </label>
        <input type="text">
      </div>
    </div>

    用你的html试试这个CSS代码。

    .container {
      display: flex;
      flex-wrap: wrap;
      flex-direction: column;
      align-items: center;
    }
    
    .item {
      background-color: orange;
      display: flex;
      align-items: center;
    }
    
    label {
      width: 100px;
      display: inline-block;
    }
    input {
      display: inline-block;
    }
    

    请检查添加的CSS ::

    .container {
      /* Flex Properties */
      display: flex;
      flex-wrap: wrap;
      flex-direction: column;
      align-items: center;
    }
    
    .item {
      background-color: orange;
    }
    
        label {
          width: 100px;
          display: inline-block;
          vertical-align: middle;
        }
    
    input {
          width: 100px;
          display: inline-block;
          vertical-align: middle;
        }
    <div class="container">
      <div class="item">
        <label>Gee my iefwaf fwats: </label>
        <input>
      </div>
    </div>
    链接地址: http://www.djcxy.com/p/76018.html

    上一篇: 在正方形(柔性)divs中垂直居中文本

    下一篇: 使用FlexBox时垂直对齐输入