使用FlexBox时垂直对齐输入

这个问题在这里已经有了答案:

  • Flexbox:水平和垂直居中8个答案

  • .item div display: flex; align-items: center display: flex; align-items: center因为它是input元素的父元素:

    .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/76017.html

    上一篇: Vertically Align Input When Using FlexBox

    下一篇: How to center a image in a div horizontally and vertically