elementplus表单位置居中

要使Element Plus表单居中显示,可以使用Flexbox布局。以下是一个简单的例子,演示如何使用CSS将表单居中:

<template>
  <el-form :model="form" label-width="80px" style="margin: 0 auto; max-width: 300px;">
    <el-form-item label="用户名">
      <el-input v-model="form.username"></el-input>
    </el-form-item>
    <el-form-item label="密码">
      <el-input type="password" v-model="form.password"></el-input>
    </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="onSubmit">提交</el-button>
    </el-form-item>
  </el-form>
</template>
<template>
  <el-form :model="form" label-width="80px" style="margin: 0 auto; max-width: 300px;">
    <el-form-item label="用户名">
      <el-input v-model="form.username"></el-input>
    </el-form-item>
    <el-form-item label="密码">
      <el-input type="password" v-model="form.password"></el-input>
    </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="onSubmit">提交</el-button>
    </el-form-item>
  </el-form>
</template>
<style>
.el-form {
  display: flex;
  justify-content: center;
  align-items: center;
  flex-direction: column;
  min-height: 100vh;
}
</style>
在这个例子中,el-form 被设置了 display: flex,并且使用了 justify-content 和 align-items 属性来使表单在页面中水平和垂直居中。flex-direction: column 是为了让表单项垂直排列。min-height: 100vh 确保表单至少有100%的视口高度,即使内容不够也会占满整个视口。
  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值