<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>
效果:
div动态居中:
.front {
z-index: 1;
position: absolute;
left: 0;
right: 0;
top: 0;
bottom: 0;
display: flex;
justify-content: center;
align-items: center;
color: #ffffff;
}
评论区