placeholder
V2EX  ›  问与答

input 这种输入框怎么水平垂直居中,请各位指点一下,实在搜不到了

  •  
  •   placeholder · Aug 1, 2022 · 1667 views
    This topic created in 1412 days ago, the information mentioned may be changed or developed.

    Grid 布局,一行两列,两列都有 input 输入框。

    怎么才能做到水平垂直居中,本职工作不忙,业余写着玩玩这家伙写的我一脑门子汗,

    搜到的居中全都是文字内容居中,没找到有这种 input 的,我试了试也没成功

    5 replies    2022-08-02 07:50:46 +08:00
    noe132
        1
    noe132  
       Aug 1, 2022
    justify-items: center;

    单行布局不是 flex 更好用么?写 flex-direction: column; align-items: center 也能实现一样的效果
    horseInBlack
        2
    horseInBlack  
       Aug 1, 2022
    一行两列用 flex ,每列内部也用 flex

    <div class="container">
    <div class="left item">
    姓名:<input type="text">
    </div>
    <div class="right item">
    年龄:<input type="text">
    </div>
    </div>

    .container{
    width: 100%;
    height:200px;
    border:2px solid black;

    display:flex;
    }

    .item{
    flex:1;
    display:flex;
    justify-content:center;
    align-items:center;
    border:2px solid black;

    }

    input{
    height:20px;
    }
    fox0001
        4
    fox0001  
       Aug 1, 2022 via Android
    直接 flex 解决
    placeholder
        5
    placeholder  
    OP
       Aug 2, 2022
    @noe132
    @horseInBlack
    @horseInBlack
    @fox0001

    感谢感谢,我去写一下
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   886 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 41ms · UTC 21:34 · PVG 05:34 · LAX 14:34 · JFK 17:34
    ♥ Do have faith in what you're doing.