使用HTML + CSS设计简单登录界面

使用HTML + CSS设计简单登录界面

效果展示

在这里插入图片描述

代码实现

login.html

<!DOCTYPE html>
<html lang="zh">
<head>
   <meta charset="UTF-8">
   <title>login</title>
   <link rel="stylesheet" href="../css/login-css.css">
</head>
<body>
   <form class="box" action="index.html" method="post">
      <h1>Login</h1>
      <input type="text" name="" placeholder="Username">
      <input type="password" name="" placeholder="Password">
      <input type="submit" name="" value="Login">
   </form>
</body>
</html>

login-css.css

body{
margin:0;
padding:0;
font-family:sans-serif;
background:Url(../imgs/bg.jpg);
background-repeat:no-repeat;
background-size:100% auto;
}
.box{
width:300px;
padding:40px;
position:absolute;
top:32%;
left:35%;
translate(-50%,-50%);
-webkit-transform: >translate(-50%,-50%);
-moz-transform: >translate(-50%,-50%);
-o-transform: >translate(-50%,-50%);
background:#19191970;
text-align:center;
}
.box h1{
color:white;
text-transform:uppercase;
font-weight:500;
}
.box input[type = "text"],.box input[type = "password"]{
border:0;
background:none;
display:block;
margin:20px auto;
text-align:center;
border:2px solid #3498db;
padding:14px 10px;
width:200px;
outline:none;
color:white;
border-radius:24px;
transition:0.25s;
}
.box input[type = "text"]:focus,.box input[type = "password"]:focus{
white:280px;
border-color:#2ecc71;
}
.box input[type = "submit"]{
border:0;
background:none;
display:block;
margin:20px auto;
text-align:center;
border:2px solid #3498db;
padding:14px 40px;
outline:none;
color:white;
border-radius:24px;
transition:1s;
cursor:pointer;
}
.box input[type="submit"]:hover{
background:#2ecc71;
}
  • 1
    点赞
  • 24
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: HTML、jQuery和CSS的结合可以轻松地创建一个简单登录界面。 首先,我们需要编写HTML代码来构建登录表单的结构。我们可以创建一个包含用户名和密码输入框以及提交按钮的表单元素。此外,我们还可以添加一些简单的样式来美化界面。 以下是一个示例的HTML代码: ```html <!DOCTYPE html> <html lang="zh"> <head> <meta charset="UTF-8"> <title>登录界面</title> <link rel="stylesheet" href="style.css"> </head> <body> <div class="container"> <h1>用户登录</h1> <form id="loginForm"> <label for="username">用户名:</label> <input type="text" id="username" required> <label for="password">密码:</label> <input type="password" id="password" required> <button type="submit">登录</button> </form> </div> <script src="https://code.jquery.com/jquery-3.5.1.min.js"></script> <script src="script.js"></script> </body> </html> ``` 接下来,我们需要添加一些CSS样式来美化登录界面。我们可以定义容器的样式,设置标题样式,以及定义表单元素的样式。以下是一个示例的CSS代码: ```css .container { width: 300px; margin: 0 auto; } h1 { text-align: center; font-size: 24px; } form { display: flex; flex-direction: column; } label { margin-top: 10px; } input, button { margin-bottom: 10px; } ``` 最后,在脚本文件(script.js),我们可以使用jQuery来处理表单的提交事件。我们可以通过选择器选取表单元素,并使用`submit()`方法来添加提交事件的处理函数。在处理函数,我们可以获取输入框的值,并执行相应的逻辑,例如验证用户名和密码。 以下是一个示例的脚本代码: ```javascript $(function() { $('#loginForm').submit(function(event) { event.preventDefault(); var username = $('#username').val(); var password = $('#password').val(); // 添加你的逻辑代码 // 结果处理 if (username === 'admin' && password === '123456') { alert('登录成功!'); } else { alert('用户名或密码错误!'); } }); }); ``` 通过以上的HTMLCSS和jQuery代码,我们就创建了一个简单登录界面。当用户填写用户名和密码后,点击登录按钮,我们可以根据输入的内容执行相应的逻辑,例如验证用户信息并给出相应的提示。这样,我们就成功地使用HTML、jQuery和CSS创建了一个简单登录界面。 ### 回答2: HTML 是一种用于网页结构的标记语言,CSS 是一种用于描述网页样式的语言,而 jQuery 是一个简化 JavaScript 编程的库。通过结合这三个技术,我们可以创建一个简单登录界面。 首先,在 HTML 创建一个登录界面的基本结构。我们可以使用 `<form>` 元素来创建一个表单,其包含一个输入字段用于用户名和密码,以及一个登录按钮。可以使用 `<label>` 元素来作为输入字段的标签,通过 `for` 属性与相应的输入字段关联起来。 接下来,在 CSS 设置登录界面的样式。例如,可以设置表单的宽度、边框样式、背景颜色和字体样式。 最后,在 jQuery 添加一些交互效果,例如当鼠标悬停在输入字段上时改变背景颜色,或者点击登录按钮时显示一个提示信息。 下面是一个简单的示例代码: HTML: ```html <form> <label for="username">用户名:</label> <input type="text" id="username" name="username" required><br> <label for="password">密码:</label> <input type="password" id="password" name="password" required><br> <input type="submit" value="登录"> </form> ``` CSS: ```css form { width: 300px; padding: 20px; border: 1px solid #ccc; background-color: #f9f9f9; font-family: Arial, sans-serif; } label { display: block; margin-bottom: 10px; } input[type="text"], input[type="password"] { width: 100%; padding: 5px; margin-bottom: 10px; } input[type="submit"] { width: 100%; padding: 10px; background-color: #4CAF50; color: white; border: none; cursor: pointer; } input[type="submit"]:hover { background-color: #45a049; } ``` jQuery: ```javascript // 当输入字段悬停时改变背景颜色 $('input[type="text"], input[type="password"]').hover(function(){ $(this).css('background-color', '#e6e6e6'); }, function(){ $(this).css('background-color', ''); }); // 当点击登录按钮时显示提示信息 $('input[type="submit"]').click(function(){ alert('登录成功!'); }); ``` 这是一个简单登录界面示例,当然还可以根据需求进行更复杂的设计和交互效果。 ### 回答3: 要用HTML、jQuery和CSS写一个简单登录界面,可以按照以下步骤进行: 1. 创建一个HTML文件,并使用<head>元素引入相关的CSS和JavaScript库,如下所示: ``` <!DOCTYPE html> <html> <head> <title>登录界面</title> <link rel="stylesheet" type="text/css" href="styles.css"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> <script src="script.js"></script> </head> <body> ``` 2. 在<body>元素创建一个<div>元素来容纳登录表单,如下所示: ``` <div class="login-container"> <h2>用户登录</h2> <form id="login-form"> <input type="text" id="username" placeholder="请输入用户名" required> <input type="password" id="password" placeholder="请输入密码" required> <button type="submit">登录</button> </form> </div> ``` 3. 在CSS文件(styles.css)定义登录表单的样式,如下所示: ``` .login-container { text-align: center; } h2 { margin-bottom: 20px; } input, button { padding: 10px; margin-bottom: 10px; } button { background-color: #4CAF50; color: white; border: none; } button:hover { opacity: 0.8; } ``` 4. 在JavaScript文件(script.js)使用jQuery来处理表单的提交事件,如下所示: ``` $(document).ready(function() { $('#login-form').submit(function(e) { e.preventDefault(); // 阻止表单的默认提交行为 var username = $('#username').val(); var password = $('#password').val(); // 在这里可以对用户名和密码进行验证 // 如果验证通过,则执行登录逻辑 // 可以使用ajax发送登录请求到服务器,并根据服务器的返回结果进行相应的操作 // 示例:$.post('login.php', {username: username, password: password}, function(response) { ... }); }); }); ``` 以上就是一个用HTML、jQuery和CSS编写的简单登录界面的示例。你可以根据需要对样式和JavaScript逻辑进行进一步的修改和扩展。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值