• 基于 HTML5/CSS3 制作漂亮的登录页面


    HTML5 是对 HTML 标准的第五次修订。其主要的目标是将互联网语义化,以便更好地被人类和机器阅读,并同时提供更好地支持各种媒体的嵌入。HTML5是互联网的下一代标准,被认为是互联网的核心技术之一。CSS3是CSS(层叠样式表)技术的升级版本,CSS3原CSS基础上新增了很多新特征。

    此项目基于 HTML5/CSS3 制作漂亮的登录页面,教学目标:

    • CSS3 设置背景图像
    • CSS3 圆角/透明效果实现
    • CSS 属性选择器/伪类选择器
    • CSS3 过滤效果语法使用

    第一步:编写登录静态默认页面布局

    利用HTML基础标签,实现登录静态默认页面布局。

    目录结构:

    pretty-login/        --根目录
      ├── css/            --css文件目录
      └── images/         --图片文件目录  
      index.html          --入口html文件

    免费的图片库资源:

    Hippopx - beautiful free stock photos

    PickPik - Beautiful Royalty-Free Photos Sorted By AI

    Gratisography - Free High-Resolution Stock Photos

    index.html

    1. html>
    2. <html lang="en">
    3. <head>
    4. <meta charset="UTF-8">
    5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
    6. <meta http-equiv="X-UA-Compatible" content="ie=edge">
    7. <title>shixun.onlinetitle>
    8. <link rel="stylesheet" href="css/style.css">
    9. head>
    10. <body>
    11. body>
    12. html>

    style.css

    1. body {
    2. margin: 0;
    3. padding: 0;
    4. background-image: url(../images/bg.jpg);
    5. background-repeat: no-repeat;
    6. background-size: cover;
    7. }

    第二步:编写登录页面主窗口

    index.html 

    1. html>
    2. <html lang="en">
    3. <head>
    4. <meta charset="UTF-8">
    5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
    6. <meta http-equiv="X-UA-Compatible" content="ie=edge">
    7. <title>shixun.onlinetitle>
    8. <link rel="stylesheet" href="css/style.css">
    9. head>
    10. <body>
    11. <form class="login-form" action="#" method="POST">
    12. <h1>实训在线-登录h1>
    13. form>
    14. body>
    15. html>

    style.css

    1. .container {
    2. width: 300px;
    3. height: 400px;
    4. /* 水平居中 */
    5. margin: 150px auto;
    6. padding: 20px;
    7. /* border: 1px solid #000000; */
    8. position: relative;
    9. }
    10. .container h2 {
    11. text-align: center;
    12. font-size: 20px;
    13. color: #478fb7;
    14. }
    15. .container img {
    16. width: 120px;
    17. height: 95px;
    18. /* 绝对定位 */
    19. position: absolute;
    20. top: -20%;
    21. left: 50%;
    22. /* 将指定元素向左移动其自身宽度的 50% ,实现将其水平居中*/
    23. transform: translate(-50%, 0);
    24. }
    25. .container input {
    26. width: 100%;
    27. padding: 10px 15px;
    28. border: 1px solid #dddddd;
    29. /* 添加圆角效果 */
    30. border-radius: 50px;
    31. margin-bottom: 20px;
    32. /* 去掉外边框 */
    33. outline: none;
    34. font-size: 14px;
    35. /* CSS3 提供的属性,设置元素的宽度包含其 padding 和 border 的宽度 */
    36. box-sizing: border-box;
    37. }
    38. /* > 表示设置当前元素下的直接子元素(儿子元素) */
    39. .username>img {
    40. /* 隐藏元素 */
    41. display: none;
    42. width: 120px;
    43. height: 113px;
    44. }
    45. /* :focus 当前元素获得焦点 */
    46. /* :focus-within 当前元素或其子元素获得焦点 */
    47. .username:focus-within>img {
    48. display: block;
    49. }
    50. .username:focus-within>input {
    51. /* 修改输入框的边框颜色 */
    52. border-color: #f29855;
    53. }
    54. /* ~表示定位当前元素后的所有兄弟元素 */
    55. /* 当前 class=username 的元素或其子元素获得焦点时,隐藏其后的同级兄弟 img 元素 */
    56. .username:focus-within~img {
    57. display: none;
    58. }

     第三步:编写“用户名”&“密码”输入框

    index.html 

    1. html>
    2. <html lang="en">
    3. <head>
    4. <meta charset="UTF-8">
    5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
    6. <meta http-equiv="X-UA-Compatible" content="ie=edge">
    7. <title>shixun.onlinetitle>
    8. <link rel="stylesheet" href="css/style.css">
    9. head>
    10. <body>
    11. <form class="login-form" action="#" method="POST">
    12. <h1>实训在线-登录h1>
    13. <input type="text" name="name" placeholder="用户名...">
    14. <input type="password" name="password" placeholder="密码...">
    15. form>
    16. body>
    17. html>

    style.css

    1. body {
    2. margin: 0;
    3. padding: 0;
    4. background-image: url(../images/bg.jpg);
    5. background-repeat: no-repeat;
    6. background-size: cover;
    7. }
    8. .login-form {
    9. width: 300px;
    10. background: #191919;
    11. padding: 30px;
    12. /* 水平居中处理 */
    13. margin: 10% auto 0 auto;
    14. /* 圆角效果 */
    15. border-radius: 30px;
    16. opacity: 0.6;
    17. text-align: center;
    18. }
    19. .login-form h1 {
    20. color: white;
    21. font-weight: 500;
    22. }
    23. .login-form input[type="text"], .login-form input[type="password"] {
    24. background: none;
    25. width: 200px;
    26. border: 2px solid #3498db;
    27. border-radius: 25px;
    28. font-size: 16px;
    29. margin: 10px auto;
    30. padding: 14px 10px;
    31. text-align: center;
    32. outline: none;
    33. color: white;
    34. /* CSS3 过渡效果,设置时长 */
    35. transition: 0.25s;
    36. }
    37. .login-form input[type="text"]:focus, .login-form input[type="password"]:focus {
    38. width: 280px;
    39. border-color: #2ecc71;
    40. }

    第四步:编写“登录”&“重置”按钮

    index.html

    1. html>
    2. <html lang="en">
    3. <head>
    4. <meta charset="UTF-8">
    5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
    6. <meta http-equiv="X-UA-Compatible" content="ie=edge">
    7. <title>shixun.onlinetitle>
    8. <link rel="stylesheet" href="css/style.css">
    9. head>
    10. <body>
    11. <form class="login-form" action="#" method="POST">
    12. <h1>实训在线-登录h1>
    13. <input type="text" name="name" placeholder="用户名...">
    14. <input type="password" name="password" placeholder="密码...">
    15. <input type="submit" value="登 录">
    16. <input type="reset" value="重 置">
    17. form>
    18. body>
    19. html>

    style.css (同上)

    查看效果

    项目总结,通过此项目的学习了解以下知识点内容:

    • 掌握如何利用 CSS3 设置背景图片:background-image: url(../img/bg.jpg)
    • 掌握如何利用 CSS3 设置元素的透明效果:opacity: 0.6;
    • 掌握如何利用 CSS3 设置圆角效果:border-radius: 25px;
    • 掌握如何利用 CSS3 实现过渡效果:transition: 0.25s;
    • 掌握 CSS 中属性选择器和伪类选择器的使用方法
  • 相关阅读:
    Rust根据条件删除相邻元素:dedup
    1766. 互质树 DFS+桶
    Candence Virtuoso基本电路设计(一)
    微前端一:技术选型
    计算机网络知识点总结(每日更新)
    第6章 如何产生优秀的 Micro SaaS 创意
    分片并不意味着分布式
    markdown语法整理
    【TypeScript】带类型语法的JavaScript
    SpringBoot-JSR303数据校验
  • 原文地址:https://blog.csdn.net/iamcnnetiger/article/details/127107621