html+css实现一个动态登录页面

效果如下:
在这里插入图片描述
后面的泡泡是动态的,只能截图,所以后面不动了,代码如下

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style type="text/css">
        * {
    
            box-sizing: border-box;
        }
        body {
    
            margin: 0;
            padding: 0;
            font: 16px/20px microsft yahei;
         }
        .wrap {
    
            width: 100%;
            height: 100%;
            padding: 10% 0;
            position: fixed;
            opacity: 0.8;
            background: linear-gradient(to bottom right,#000000, #656565);
            background: -webkit-linear-gradient(to bottom right,#50a3a2,#53e3a6);
        }
        .container {
    
            width: 60%;
            margin: 0 auto;
        }
        .container h1 {
    
            text-align: center;
            color: #FFFFFF;
            font-weight: 500;
        }
        .container input {
    
            width: 320px;
            display: block;
            height: 36px;
            border: 0;
            outline: 0;
            padding: 6px 10px;
            line-height: 24px;
            margin: 32px auto;
            -webkit-transition: all 0s ease-in 0.1ms;
            -moz-transition: all 0s ease-in 0.1ms;
            transition: all 0s ease-in 0.1ms;
        }
        .container input[type="text"] , .container input[type="password"]  {
    
            background-color: #FFFFFF;
            font-size: 16px;
            color: #50a3a2;
        }
        .container input[type='submit'] {
    
            font-size: 16px;
            letter-spacing: 2px;
            color: #666666;
         
  • 3
    点赞
  • 44
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
### 回答1: 作为一名AI语言模型,我无法为您提供完整的后端实现。但是,我可以向您展示如何使用HTMLCSS和JavaScript创建一个简单的登录界面,并提供一个示例API以供参考。 HTML代码: ``` <!DOCTYPE html> <html> <head> <title>Login Page</title> <link rel="stylesheet" href="style.css"> </head> <body> <form> <h2>Login Form</h2> <label for="username">Username:</label> <input type="text" id="username" name="username" placeholder="Enter username"><br> <label for="password">Password:</label> <input type="password" id="password" name="password" placeholder="Enter password"><br> <button type="button" id="login-btn">Login</button> <div id="error-message"></div> </form> <script src="script.js"></script> </body> </html> ``` CSS代码: ``` form { width: 400px; margin: 0 auto; text-align: center; } h2 { font-size: 30px; margin-bottom: 30px; } label { display: inline-block; width: 100px; text-align: left; margin-bottom: 10px; } input { display: block; width: 100%; padding: 10px; margin-bottom: 20px; border: 2px solid #ccc; border-radius: 5px; } button { background-color: #4CAF50; color: white; padding: 10px 20px; border: none; border-radius: 5px; cursor: pointer; } #error-message { color: red; font-weight: bold; margin-top: 20px; } ``` JavaScript代码: ``` const loginBtn = document.getElementById("login-btn"); const errorMessage = document.getElementById("error-message"); loginBtn.addEventListener("click", function() { const username = document.getElementById("username").value; const password = document.getElementById("password").value; const xhr = new XMLHttpRequest(); const url = "https://example.com/api/login"; xhr.open("POST", url, true); xhr.setRequestHeader("Content-Type", "application/json"); xhr.onreadystatechange = function() { if (xhr.readyState === 4) { if (xhr.status === 200) { const response = JSON.parse(xhr.responseText); if (response.success) { alert("Login successful!"); } else { errorMessage.textContent = response.message; } } else { errorMessage.textContent = "Error occurred while logging in."; } } }; const data = JSON.stringify({ username: username, password: password }); xhr.send(data); }); ``` 请注意,此示例仅用于说明目的。在实际应用中,您需要使用更严格的安全措施来保护用户的凭据,并防止攻击。 至于后端实现,由于每个应用程序的需求不同,您需要根据自己的需求编写自己的API。不过,下面是一个简单的Node.js示例,它接受POST请求并将用户名和密码与硬编码的凭据进行比较: ``` const express = require("express"); ### 回答2: 要实现一个登录界面和接口,可以使用HTMLCSS和JavaScript编写代码。首先,我们可以创建一个HTML文件作为登录界面的基础。 HTML代码如下: ``` <!DOCTYPE html> <html> <head> <title>登录界面</title> <link rel="stylesheet" type="text/css" href="style.css"> </head> <body> <div class="container"> <h1>用户登录</h1> <form id="loginForm"> <input type="text" id="username" placeholder="用户名"> <input type="password" id="password" placeholder="密码"> <button type="submit">登录</button> </form> </div> <script src="script.js"></script> </body> </html> ``` 接下来,我们可以创建一个CSS文件来美化登录界面的样式。 CSS代码如下(style.css): ```css .container { width: 300px; margin: 0 auto; padding: 20px; background-color: #f2f2f2; text-align: center; } h1 { margin-bottom: 20px; } input, button { width: 100%; margin-bottom: 10px; padding: 10px; } button { background-color: #4CAF50; color: white; cursor: pointer; } ``` 最后,我们可以创建一个JavaScript文件来处理登录界面的交互和接口请求。 JavaScript代码如下(script.js): ```javascript document.getElementById('loginForm').addEventListener('submit', function(event){ event.preventDefault(); // 阻止表单提交默认行为 var username = document.getElementById('username').value; var password = document.getElementById('password').value; // 发送登录请求到后台接口 // 可以使用XMLHttpRequest、fetch或者其他HTTP请求库发送请求到后台接口进行验证 // 在这里演示一个假设的登录验证逻辑 if(username === 'admin' && password === 'password') { alert('登录成功!'); } else { alert('用户名或密码错误!'); } }); ``` 这样,我们就实现一个简单的登录界面和接口。用户输入用户名和密码后,会在点击登录按钮时触发JavaScript代码中的登录请求逻辑,并根据用户名和密码的正确与否给出相应的提示。 ### 回答3: HTML部分: ``` <!DOCTYPE html> <html> <head> <title>登录界面</title> <style> /* CSS样式 */ body { background-color: #f4f4f4; font-family: Arial, sans-serif; margin: 0; padding: 0; } .container { width: 300px; margin: 100px auto; padding: 20px; background-color: #fff; border-radius: 5px; box-shadow: 0px 0px 5px rgba(0, 0, 0, 0.3); } h1 { text-align: center; } input[type="text"], input[type="password"] { width: 100%; padding: 10px; margin-bottom: 10px; border: 1px solid #ccc; border-radius: 3px; box-sizing: border-box; } input[type="submit"] { width: 100%; padding: 10px; background-color: #4CAF50; color: #fff; border: none; border-radius: 3px; cursor: pointer; } </style> </head> <body> <div class="container"> <h1>用户登录</h1> <form id="loginForm"> <input type="text" id="username" name="username" placeholder="用户名" required> <input type="password" id="password" name="password" placeholder="密码" required> <input type="submit" value="登录"> </form> </div> <script src="script.js"></script> </body> </html> ``` CSS样式部分设置了页面的背景颜色、字体、容器的样式、输入框和按钮的样式。 JS部分: ``` window.onload = function() { document.getElementById("loginForm").addEventListener("submit", function(event) { event.preventDefault(); // 阻止表单提交的默认行为 var username = document.getElementById("username").value; var password = document.getElementById("password").value; // 使用fetch API发送POST请求到登录接口 fetch("login.php", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ username: username, password: password }) }) .then(function(response) { return response.json(); }) .then(function(data) { if (data.success) { alert("登录成功"); // 在这里可以处理登录成功后的操作,如跳转到其他页面 } else { alert("登录失败,请检查用户名和密码"); } }) .catch(function(error) { console.error("登录请求出错: ", error); }); }); } ``` JS部分将监听登录表单的提交事件,并使用fetch API发送POST请求到登录接口,接收返回的数据来判断登录是否成功,根据判断结果弹出相应的提示框。 接口部分: ``` <?php // 根据接收到的用户名和密码进行验证,返回一个JSON对象表示登录结果 $username = $_POST["username"]; $password = $_POST["password"]; // 进行用户名和密码的验证逻辑,这里以简单的示例为例 if ($username == "admin" && $password == "123456") { $response = array("success" => true); } else { $response = array("success" => false); } header("Content-Type: application/json"); echo json_encode($response); ?> ``` 接口部分使用PHP编写,接收前端发送的POST请求,根据用户名和密码进行验证,然后返回一个JSON对象表示登录结果。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值