V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
placeholder
V2EX  ›  问与答

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

  •  
  •   placeholder · 2022-08-01 20:55:42 +08:00 · 994 次点击
    这是一个创建于 626 天前的主题,其中的信息可能已经有所发展或是发生改变。

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

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

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

    5 条回复    2022-08-02 07:50:46 +08:00
    noe132
        1
    noe132  
       2022-08-01 21:16:00 +08:00
    justify-items: center;

    单行布局不是 flex 更好用么?写 flex-direction: column; align-items: center 也能实现一样的效果
    horseInBlack
        2
    horseInBlack  
       2022-08-01 21:30:51 +08:00
    一行两列用 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;
    }
    horseInBlack
        3
    horseInBlack  
       2022-08-01 21:31:01 +08:00
    fox0001
        4
    fox0001  
       2022-08-01 23:32:06 +08:00 via Android
    直接 flex 解决
    placeholder
        5
    placeholder  
    OP
       2022-08-02 07:50:46 +08:00
    @noe132
    @horseInBlack
    @horseInBlack
    @fox0001

    感谢感谢,我去写一下
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5723 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 508ms · UTC 02:00 · PVG 10:00 · LAX 19:00 · JFK 22:00
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.