0
点赞
收藏
分享

微信扫一扫

大学课程-人机交互期末复习

以沫的窝 2024-09-07 阅读 28

要使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%的视口高度,即使内容不够也会占满整个视口。
举报

相关推荐

0 条评论