如何用html+CSS实现精美登录页面?看了的小伙伴都直呼简单!!

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

实现过程:
在html网页中先定义一个表单以后,再定义一个Login标题,两个输入框,最后一个登录按键,主要功夫为css配置。

  1. 先定义页面主体,标准的消内外边距
body {
     margin:0;
     padding:0;
     font-family:sans-serif;
     background-color: #ecf0f1;
 }
  1. 定义表单整体样式
 .box {
     width:300px;
     padding:40px;
     top:50%;
     left:50%;
     transform: translate(-50%,-50%);
     position:absolute;
     background-color: #34495e;
     text-align: center;
 }
  1. 定义该表单中两个文本输入框的样式,可以根据喜好调整transition的动画时间
.box input[type="text"],.box input[type="password"] {
     background: none;
     display: block;
     text-align: center;
     border:0;
     margin:20px auto;
     border:2px solid #2980b9;
     padding:14px 10px;
     width:200px;
     outline:none;
     color:white;
     border-radius: 24px;
     transition: 0.5s;
 }
  1. 定义当光标放在两个输入框时的样式,这里我只是简单的变宽和蓝色变亮
.box input[type="text"]:focus,.box input[type="password"]:focus {
     width:280px;
     border-color:#3498db;
 }
  1. 定义提交按钮的样式
 .box input[type="submit"] {
    color:white;
    background: none;
    display: block;
    text-align: center;
    border:0;
    margin:20px auto;
    border:2px solid #2ecc71;
    padding:14px 10px;
    cursor:pointer;
    width:180px;
    outline:none;
    border-radius: 24px;
    transition: 0.25s;
 }
  1. 定义提交按钮的选中样式,这里我简单把背景调成对应绿色,就已经很好看了
.box input[type="submit"]:hover{
     background-color: #2ecc71;
 }

7.大概完成后,发现页面标题默认黑色与表单背景颜色不太符合,因此调成白色即可

h1 {
    color:#ecf0f1;
}

本页面全部代码如下:
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>Document</title>
    <link href="style.css" type="text/css" rel="stylesheet">
</head>
<body>
    <form class="box" method="post">
        <h1>Login</h1>
        <input type="text" name="firstName" placeholder="账户名称">
        <input type="password" name="firstPassword" placeholder="密码">
        <input type="submit" name="firstSubmit" value="登录">

    </form>
</body>
</html>

CSS中:


 body {
     margin:0;
     padding:0;
     font-family:sans-serif;
     background-color: #ecf0f1;
 }

 .box {
     width:300px;
     padding:40px;
     top:50%;
     left:50%;
     transform: translate(-50%,-50%);
     position:absolute;
     background-color: #34495e;
     text-align: center;
 }

 .box input[type="text"],.box input[type="password"] {
     background: none;
     display: block;
     text-align: center;
     border:0;
     margin:20px auto;
     border:2px solid #2980b9;
     padding:14px 10px;
     width:200px;
     outline:none;
     color:white;
     border-radius: 24px;
     transition: 0.5s;
 }

 .box input[type="text"]:focus,.box input[type="password"]:focus {
     width:280px;
     border-color:#3498db;
 }

 .box input[type="submit"] {
    color:white;
    background: none;
    display: block;
    text-align: center;
    border:0;
    margin:20px auto;
    border:2px solid #2ecc71;
    padding:14px 10px;
    cursor:pointer;
    width:180px;
    outline:none;
    border-radius: 24px;
    transition: 0.25s;
 }

 .box input[type="submit"]:hover{
     background-color: #2ecc71;
 }

 h1 {
    color:#ecf0f1;
}



如果你喜欢该篇文章,请不要忘记点击右下角的大拇指进行点赞噢~

欢迎大家关注我的公众号:Smooth前端成长记录
公众号同步更新CSDN博客内容,想方便阅读博客的C友可以来关注我的公众号以便获得更优良的阅读体验~
在这里插入图片描述

  • 8
    点赞
  • 58
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
以下是HTML制作登录页面的基本步骤和代码示例: 1. 创建HTML文件并添加基本结构 ```html <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>登录页面</title> </head> <body> <!-- 在这里添加页面内容 --> </body> </html> ``` 2. 添加页面内容,包括表单和相关元素 ```html <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>登录页面</title> </head> <body> <h1>欢迎登录</h1> <form> <label for="username">用户名:</label> <input type="text" id="username" name="username"><br><br> <label for="password">密码:</label> <input type="password" id="password" name="password"><br><br> <input type="submit" value="登录"> </form> </body> </html> ``` 3. 样式美化,可以使用CSS来设置样式 ```html <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>登录页面</title> <style> body { background-color: #f2f2f2; font-family: Arial, sans-serif; } h1 { text-align: center; color: #333; } form { width: 300px; margin: 0 auto; background-color: #fff; padding: 20px; border-radius: 5px; box-shadow: 0 0 10px rgba(0,0,0,0.2); } label { display: block; margin-bottom: 10px; color: #666; } input[type="text"], input[type="password"] { width: 100%; padding: 10px; border-radius: 5px; border: none; margin-bottom: 20px; box-sizing: border-box; } input[type="submit"] { background-color: #4CAF50; color: #fff; border: none; padding: 10px 20px; border-radius: 5px; cursor: pointer; } input[type="submit"]:hover { background-color: #3e8e41; } </style> </head> <body> <h1>欢迎登录</h1> <form> <label for="username">用户名:</label> <input type="text" id="username" name="username"><br><br> <label for="password">密码:</label> <input type="password" id="password" name="password"><br><br> <input type="submit" value="登录"> </form> </body> </html> ```

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值