侧边栏壁纸
博主头像
分享你我博主等级

行动起来,活在当下

  • 累计撰写 107 篇文章
  • 累计创建 13 个标签
  • 累计收到 0 条评论

目 录CONTENT

文章目录

vue + element 实现登录表单 并实现div动态居中

管理员
2020-10-12 / 0 评论 / 0 点赞 / 3 阅读 / 8842 字
<template>
  <div>
    <div class="background">
      <img :src="imgSrc" width="100%" height="100%" alt="" />
    </div>
    <div class="front">
      <el-card class="card">
        <div slot="header" class="title">
          <span>電子站牌發饰後台管理系統</span>
        </div>
        <div>
          <el-form
            :model="login"
            :rules="rules"
            status-icon
            ref="login"
            label-width="0px"
            class="demo-ruleForm"
          >
            <el-form-item prop="username">
              <el-input
                v-model="login.username"
                placeholder="用户名"
                autofocus="off"
                autocomplete="off"
              ></el-input>
            </el-form-item>
            <el-form-item prop="password">
              <el-input
                type="password"
                v-model="login.password"
                placeholder="密码"
                autocomplete="off"
              ></el-input>
            </el-form-item>
            <el-form-item size="medium">
              <el-button style="float: right;" type="primary">登录</el-button>
            </el-form-item>
          </el-form>
        </div>
      </el-card>
    </div>
  </div>
</template>
<script>
export default {
  data() {
    return {
      imgSrc: require("../../../public/image/login.jpg"),
      login: {
        username: "",
        password: ""
      },
      rules: {
        username: [
          { required: true, message: "请输入用户名", trigger: "blur" },
          { min: 3, max: 5, message: "长度在 3 到 5 个字符", trigger: "blur" }
        ],
        password: [
          { required: true, message: "请输入密码", trigger: "blur" },
          {
            type: "password",
            min: 8,
            max: 16,
            message: "长度在 8 到 16 个字符",
            trigger: "blur"
          }
        ]
      }
    };
  }
};
</script>
<style scoped>
.background {
  height: 100%;
  width: 100%;
  z-index: -1;
  padding: 0;
  margin: 0;
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  right: 0;
  background-image: "../../../public/image/login.jpg";
}
.front {
  z-index: 1;
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  color: #ffffff;
}
.card {
  width: 400px;
  background-color: rgba(
    200,
    200,
    200,
    0.3
  ); /**rgba中的a为alpha通道, 为不透明参数,.0即为完全透明*/
  border-color: rgba(200, 200, 200, 0.5);
  border-radius: 18px;
  z-index: 2;
}
.title {
  text-align: center;
  font-size: 24px;
  color: #ffffff;
}
</style>

效果:

微信截图_20201012122856.png


div动态居中:


.front {
  z-index1;
  position: absolute;
  left0;
  right0;
  top0;
  bottom0;
  display: flex;
  justify-content: center;
  align-items: center;
  color: #ffffff;
}


0

评论区