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

<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;
}


本文作者:admin

本文链接:https://www.javalc.com/post/24.html

版权声明:本篇文章于2020-10-12,由admin发表,转载请注明出处:分享你我。如有疑问,请联系我们

VUE 引入element ui 样式不生效解决

发表评论

取消
扫码支持