博客列表 >登录表单、简单后台架构 、元素样式来源与优先级的小结

登录表单、简单后台架构 、元素样式来源与优先级的小结

Breeze blue sea
Breeze blue sea原创
2022年03月21日 17:56:08390浏览

1.登入表单

代码:

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <title>Document</title>
  8. </head>
  9. <body>
  10. <!-- method 数据提交方式:get(不安全)跟post -->
  11. <form action="check.php" method="post">
  12. <div>
  13. <label for="username">用户名:</label>
  14. <input type="text" id="username" name="username" value="" placeholder="至少8位" autofocus required>
  15. </div>
  16. <div>
  17. <label for="psw">密码:</label>
  18. <input type="text" id="psw" name="password" value="" placeholder="数字+字母">
  19. </div>
  20. <div>
  21. <label for="my-email">邮箱:</label>
  22. <input type="email" id="my-email" name="email" value="" placeholder="a@email.com" required>
  23. </div>
  24. <div>
  25. <!-- 所有的input.name 相同才可以进行单选 -->
  26. <label for="male">性别:</label>
  27. <input type="radio" name="gender" id="male" >
  28. <label for="male"></label>
  29. <input type="radio" name="gender" id="female" checked>
  30. <label for="female"></label>
  31. </div>
  32. <div>
  33. <!-- 所有的input.name 数组形式 -->
  34. <label for="male">兴趣:</label>
  35. <input type="checkbox" name="hobbies[]" id="game" checked>
  36. <label for="game">游戏</label>
  37. <input type="checkbox" name="hobbies" id="music">
  38. <label for="music">音乐</label>
  39. <input type="checkbox" name="hobbies" id="fitness">
  40. <label for="fitness">健身</label>
  41. <input type="checkbox" name="hobbies" id="Photography">
  42. <label for="Photography">摄影</label>
  43. </div>
  44. <div>
  45. <!-- selected:默认值 -->
  46. <label for="province">省份</label>
  47. <select name="" id="province">
  48. <option value="1">福建</option>
  49. <option value="2">浙江</option>
  50. <option value="3">江西</option>
  51. <option value="4" selected>广东</option>
  52. </select>
  53. </div>
  54. <div>
  55. <button>提交</button>
  56. </div>
  57. </form>
  58. </body>
  59. </html>

演示图片

2.简单后台框架

代码

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <title>Document</title>
  8. <style>
  9. body {
  10. height: 100vh;
  11. width: 100vw;
  12. display: grid;
  13. grid-template-columns: 10em 1fr;
  14. grid-template-rows: 6em 1fr;
  15. margin: 0;
  16. }
  17. body .header {
  18. grid-column-end: span 2;
  19. border-bottom: 1px solid currentColor;
  20. background-color: #efe;
  21. padding: 2em;
  22. display: flex;
  23. align-items: center;
  24. }
  25. body .header div {
  26. margin-left: auto;
  27. }
  28. body .nav {
  29. background-color: #efc;
  30. margin: 0;
  31. padding-top: 1em;
  32. list-style: none;
  33. }
  34. body iframe {
  35. width: calc(100vw - 10em);
  36. height: calc(100vh - 6em);
  37. border-left: 1px solid currentColor;
  38. }
  39. </style>
  40. </head>
  41. <body>
  42. <div class="header">
  43. <h1>管理后台</h1>
  44. <div>
  45. <span>admin</span>
  46. <a href="">退出</a>
  47. </div>
  48. </div>
  49. <ul class="nav">
  50. <li><a href="code1.html" target="content">菜单项1</a></li>
  51. <li><a href="code2.html" target="content">菜单项2</a></li>
  52. <li><a href="code3.html" target="content">菜单项3</a></li>
  53. <li><a href="code1.html" target="content">菜单项4</a></li>
  54. <li><a href="code2.html" target="content">菜单项5</a></li>
  55. </ul>
  56. <iframe src="" frameborder="1" name="content"></iframe>
  57. </body>
  58. </html>

演示图片



3.元素样式来源与优先级

HTML代码演示

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <title>Document</title>
  8. <style>
  9. .ys{color: blue;}
  10. </style>
  11. <link rel="stylesheet" href="style.css">
  12. </head>
  13. <body>
  14. <!-- 1.来源样式/浏览器样式/代理样式-->
  15. <h2>默认:黑色</h2>
  16. <!-- 2.自定义样式会覆盖默认样式 -->
  17. <h2 style="color: red;">通过内置style变成红色</h2>
  18. <!-- 3.书写顺序,同名属性会被后面覆盖(优先级相同情况) -->
  19. <h2 style="color: red; color:blue;;">后写的蓝色会覆盖红色</h2>
  20. <div style="color: red;">
  21. <!-- 某些属性会继承特征,如颜色、字体等 -->
  22. <h1>h1从div继承红色</h1>
  23. </div>
  24. <div style="color: brown;">
  25. <a href="">当A链接有自己的颜色时,不继承</a>
  26. </div>
  27. <!-- 注意盒模型的属性不能继承 -->
  28. <!-- 来源样式
  29. 1.默认样式
  30. 2.自定义样式{
  31. 1.行内样式: style属性
  32. 2.文档样式/内部样式:style标签
  33. 3.外部样式:css文档
  34. }
  35. -->
  36. <hr>
  37. <!-- 1.行内样式: style属性 -->
  38. <div style="color: red;">行内样式: style属性</div>
  39. <!-- 2.文档样式/内部样式:style标签 -->
  40. <div class="ys">内部样式:style标签</div>
  41. <!-- 3.外部样式:css文档 -->
  42. <div class="ys1">内外部样式:css文档,通过link标签添加,否则不起作用</div>
  43. <hr>
  44. <div class="content-class" id="content-id" style="color: black">
  45. 优先级关系:内联样式 > ID 选择器 > 类选择器 = 属性选择器 = 伪类选择器 > 标签选择器 = 伪元素选择器
  46. <p>最终的 color 为 black,因为内联样式比其他选择器的优先级高</p>
  47. </div>
  48. </body>
  49. </html>

CSS代码

  1. .ys1{
  2. color: blueviolet;
  3. }
  4. #content-id {
  5. color: red;
  6. }
  7. .content-class {
  8. color: blue;
  9. }
  10. div {
  11. color: grey;
  12. }

演示图

声明:本文内容转载自脚本之家,由网友自发贡献,版权归原作者所有,如您发现涉嫌抄袭侵权,请联系admin@php.cn 核实处理。
全部评论
文明上网理性发言,请遵守新闻评论服务协议