欢迎您访问 最编程 本站为您分享编程语言代码,编程技术文章!
您现在的位置是: 首页

用HTML、CSS和JS打造实战案例:动态样式下的登录注册界面(实例三)

最编程 2024-07-22 15:06:50
...

index.html

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <link rel="stylesheet" href="./style.css">
    <script src="https://cdn.staticfile.org/vue/2.6.9/vue.js"></script>
</head>

<body>
    <div id='app' class="container">
        <img src="./1.jpeg" />
        <div class="panel">
            <div class="content login">
                <div class="switch">
                    <span :class='{"active": active === "login"}' @click='go("login")'>登陆</span>
                    <span>/</span>
                    <span :class='{"active": active === "register"}' @click='go("register")'>注册</span>
                </div>
                <div class='form' id="fromLogin">
                    <template v-if='active === "register"'>
                        <div class="input"><input type="text" name="email" id='email' /><label for="email">邮箱</label></div>
                        <div class="input"><input type="text" name="Username" id="username" /><label for="username">用户名</label></div>
                        <div class="input"><input type="password" name="Password" id="Password" /><label for="Password">密码</label></div>
                        <div class="input"><input type="password" name="repeat" id="Passwordrepeat" /><label for="Passwordrepeat">重复密码</label></div>
                    </template>

                    <template v-if='active === "login"'>
                        <div class="input"><input type="text" name="Username" id="username" /><label for="username">用户名</label></div>
                        <div class="input"><input type="password" name="Password" id="Password" /><label for="Password">密码</label></div>
                    </template>

                    <span>忘记?</span>

                    <button type="submit">登陆</button>
                </div>
            </div>
        </div>
    </div>
</body>

<script>
var vue = new Vue({
    el: '#app',
    data: {
        active: 'login'
    },
    methods: {
        go (type) {
            this.active = type
        }
    },
    beforeMount () {
        
    }
})
</script>

</html>

style.css

* {
    margin: 0;
    padding: 0;
}

body {
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    font-family: miaowu;
    background: linear-gradient(45deg, rgb(80, 150, 250), rgb(245, 189, 253)) fixed;
}

.container {
    position: relative;
    width: 70rem;
}

.container img {
    width: 70rem;
}

.switch span {
    color: #ccc;
    font-size: 1.4rem;
    cursor: pointer;
}

.switch span.active {
    color: rgb(181, 154, 254);
}

.panel {
    width: 30%;
    margin: 10rem 0 0;
    position: absolute;
    right: 0;
    top: 0;

    display: flex;
    justify-content: center;
}

.form {
    width: 12rem;
    margin: 3rem 0 0;
}

.form .input {
    position: relative;
    opacity: 1;
    height: 2rem;
    width: 100%;
    margin: 2rem 0;
    transition: .4s;
}

.input input {
    outline: none;
    width: 100%;
    border: none;
    border-bottom: .1rem solid rgb(181, 154, 254);
    position: relative;
    line-height: 35px;
    background: transparent;
    z-index: 1;
}

.input label {
    position: absolute;
    left: 0;
    top: 20%;
    font-size: 1.2rem;
    color: rgb(129, 101, 207);
    transition: .3s;
}   

.input input:focus ~ label {
    top: -50%;
    font-size: .9rem;
}



.form span {
    display: block;
    color: rgb(110, 89, 167);
    font-size: .8rem;
    cursor: pointer;
}

.form button {
    border: none;
    outline: none;
    margin: 2.5rem 0 0;
    width: 100%;
    height: 3rem;
    border-radius: 3rem;
    background: linear-gradient(90deg, rgb(181, 154, 254), rgb(245, 189, 253));
    box-shadow: 0 0 8px rgb(181, 154, 254);
    cursor: pointer;
    color: white;
    font-family: miaowu;
}

#live2dcanvas {
    border: 0 !important;
}

背景图:
在这里插入图片描述

效果图:
在这里插入图片描述

在这里插入图片描述