接口写好了吗 2022-07-18 09:12 采纳率: 80.2%
浏览 50
已结题

flex布局如何垂直居中对齐

我已经用了flex把他分为两块了,左边的,因为是文字,我直接就加了行高就居中对齐了,那右边的我因为有边框,所以我文字在边框内水平居中,已经加过行高了,那么这种情况如何让右边的也垂直居中对齐呢,用flex有什么办法做到吗,还是需要用到定位或者margin之类的来对齐?

img

<template>
  <div>
    <div class="wrap">
      <div class="box">
        <img src="https://img01.yzcdn.cn/vant/cat.jpeg" alt="" style="width:50px;height:50px;">
        <span style="line-height: 50px;margin-left:10px">小王</span>
      </div>
      <div class="text">+ 关注</div>
    </div>
  </div>
</template>

<script>
export default {
  name: "App",
};
</script>

<style scoped>
.wrap{
  display: flex;
  justify-content:space-between;
}
.box{
  height: 50px;
  display: flex;
}
.text{
  height: 30px;
  width: 80px;
  border: 1px solid #ccc;
  text-align: center;
  line-height: 30px;
  border-radius: 10px;
  font-size: 14px;
}
</style>


  • 写回答

2条回答

  • 我是李大福 2022-07-18 09:15
    关注
    .wrap{
      align-items:center;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 7月26日
  • 已采纳回答 7月18日
  • 创建了问题 7月18日

悬赏问题

  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 关于#python#的问题:自动化测试