你值得拥有的登录注册页面(附赠源码)

 

 

 1.HTML代码

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

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>login/register</title>
    <link rel="shortcut icon" href="favicon.ico" type="image/x-icon">
    <link rel="stylesheet" href="./day1.css">
</head>

<body>
    <!-- login/register container -->
    <div class="container">
        <!-- register -->
        <div class="form-container sign-up-container">
            <div class="form">
                <h2>sign up</h2>
                <input type="text" name="username" id="username" placeholder="Username...">
                <input type="email" name="emal" id="email" placeholder="Email...">
                <input type="password" name="password" id="password" placeholder="Password...">
                <button class="signUp">sign up</button>
            </div>
        </div>
        <!-- login -->
        <div class="form-container sign-in-container">
            <div class="form">
                <h2>sign in</h2>
                <input type="email" name="emal" id="email" placeholder="Email...">
                <input type="password" name="password" id="password" placeholder="Password...">
                <a href="#" class="forget-password">forget your password</a>
                <button class="signIn">sign in</button>
            </div>
        </div>
        <!-- overlay container -->
        <div class="overlay_container">
            <div class="overlay">
                <!-- overlay left -->
                <div class="overlay_panel overlay_left_container">
                    <h2>welcome back!</h2>
                    <p>To keep connected with us please login with your personal info</p>
                    <button id="sign-in">sign in</button>
                </div>
                <!-- overlay right -->
                <div class="overlay_panel overlay_right_container">
                    <h2>hello friend!</h2>
                    <p>Enter your personal details and start journey with us</p>
                    <button id="sign-up">sign up</button>
                </div>
            </div>
        </div>
    </div>


    <script src="./day1.js"></script>
</body>

</html>

2.CSS代码

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    background-color: #f6f5f7;
}

h2 {
    margin-bottom: 10px;
    font-size: 32px;
    text-transform: capitalize;
}

.container {
    position: relative;
    width: 768px;
    height: 480px;
    background-color: white;
    box-shadow: 0 14px 28px rgba(0, 0, 0, 0.25), 0 10px 10px rgba(0, 0, 0, 0.2);
    border-radius: 10px;
    overflow: hidden;
}

.form-container {
    position: absolute;
    top: 0;
    width: 50%;
    height: 100%;
    background-color: white;
    transition: all 0.6s ease-in-out;
}

.form {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    height: 100%;
    width: 100%;
    padding: 0 50px;
}

input {
    width: 100%;
    margin: 8px 0;
    padding: 12px;
    background-color: #eee;
    border: none;
}

.forget-password {
    display: inline-block;
    height: 20px;
    text-decoration: none;
    color: #bbb;
    text-transform: capitalize;
    font-size: 12px;
}

.forget-password:hover {
    color: lightslategray;
    border-bottom: 2px solid #ff4b2b;
}

button {
    background: #ff4b2b;
    padding: 10px 50px;
    border: 1px solid transparent;
    border-radius: 20px;
    text-transform: uppercase;
    color: white;
    margin-top: 10px;
    outline: none;
    transition: transform 80;
}

button:active {
    transform: scale(0.95);
}

.overlay_container {
    position: absolute;
    top: 0;
    width: 50%;
    height: 100%;
    z-index: 100;
    right: 0;
    overflow: hidden;
    transition: all 0.6s ease-in-out;
}

.overlay {
    position: absolute;
    width: 200%;
    height: 100%;
    left: -100%;
    background-color: #ff4b2b;
}

.overlay_panel {
    position: absolute;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    width: 50%;
    height: 100%;
    color: white;
    padding: 0 40px;
    text-align: center;
}

.overlay_panel button {
    background-color: transparent;
    border: 1px solid white;
}

.overlay_panel p {
    font-size: 12px;
    margin: 10px 0 15px 0;
}

.overlay_right_container {
    right: 0;
}

.container.active .sign-up-container {
    transform: translateX(100%);
    z-index: 5;
}

.container.active .sign-in-container {
    transform: translateX(100%);
}

.container.active .overlay_container {
    transform: translateX(-100%);
}

.container.active .overlay {
    transform: translateX(50%);
}

3.javascript代码

const container = document.getElementsByClassName('container')[0];
const signIn = document.getElementById('sign-in');
const signUp = document.getElementById('sign-up');

signUp.onclick = function() {
    container.classList.add('active');
}
signIn.onclick = function() {
    container.classList.remove('active');
}

  • 2
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
这里提供一个简单的网页注册登录代码,使用 PHP 和 MySQL 数据库。 1. 创建数据库 首先需要创建一个名为 `users` 的数据库,包含下面两个字段: - `id`:用户 ID,自增长整数类型。 - `username`:用户名,字符串类型。 - `password`:密码,字符串类型。 可以使用下面的 SQL 语句创建: ``` CREATE DATABASE users; USE users; CREATE TABLE users ( id INT(11) AUTO_INCREMENT PRIMARY KEY, username VARCHAR(50) NOT NULL, password VARCHAR(255) NOT NULL ); ``` 2. 注册页面 在 HTML 页面中创建一个注册表单,用户输入用户名和密码。提交表单时,将数据发送到 PHP 脚本进行处理。下面是示例代码: ``` <!DOCTYPE html> <html> <head> <title>注册</title> </head> <body> <h1>注册新用户</h1> <form action="register.php" method="post"> <label>用户名:</label> <input type="text" name="username"><br> <label>密码:</label> <input type="password" name="password"><br> <input type="submit" value="注册"> </form> </body> </html> ``` 3. 注册处理 在 PHP 脚本 `register.php` 中处理表单数据。首先连接数据库,然后执行插入语句将新用户信息插入数据库。最后显示注册成功或失败的消息。下面是示例代码: ``` <?php // 连接数据库 $dbhost = 'localhost'; $dbuser = 'root'; $dbpass = ''; $dbname = 'users'; $conn = mysqli_connect($dbhost, $dbuser, $dbpass, $dbname); // 处理表单数据 $username = $_POST['username']; $password = password_hash($_POST['password'], PASSWORD_DEFAULT); $sql = "INSERT INTO users (username, password) VALUES ('$username', '$password')"; if (mysqli_query($conn, $sql)) { echo "注册成功!"; } else { echo "注册失败:" . mysqli_error($conn); } // 关闭数据库连接 mysqli_close($conn); ?> ``` 4. 登录页面 在 HTML 页面中创建一个登录表单,用户输入用户名和密码。提交表单时,将数据发送到 PHP 脚本进行处理。下面是示例代码: ``` <!DOCTYPE html> <html> <head> <title>登录</title> </head> <body> <h1>用户登录</h1> <form action="login.php" method="post"> <label>用户名:</label> <input type="text" name="username"><br> <label>密码:</label> <input type="password" name="password"><br> <input type="submit" value="登录"> </form> </body> </html> ``` 5. 登录处理 在 PHP 脚本 `login.php` 中处理表单数据。首先连接数据库,然后执行查询语句获取输入用户名对应的密码。如果密码正确,则显示登录成功消息。否则显示登录失败消息。下面是示例代码: ``` <?php // 连接数据库 $dbhost = 'localhost'; $dbuser = 'root'; $dbpass = ''; $dbname = 'users'; $conn = mysqli_connect($dbhost, $dbuser, $dbpass, $dbname); // 处理表单数据 $username = $_POST['username']; $password = $_POST['password']; $sql = "SELECT * FROM users WHERE username = '$username'"; $result = mysqli_query($conn, $sql); $row = mysqli_fetch_assoc($result); if (password_verify($password, $row['password'])) { echo "登录成功!"; } else { echo "登录失败:用户名或密码错误。"; } // 关闭数据库连接 mysqli_close($conn); ?> ``` 以上是一个简单的网页注册登录代码,可以根据实际需求进行修改和扩展。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值