(一)Form用户注册表单

  1. //css样式
  2. body {
  3. background-image: url(xmemphis-colorful.webp);
  4. }
  5. .register {
  6. width: 580px;
  7. height: 380px;
  8. padding: 20px;
  9. background-color: #fff;
  10. position: fixed;
  11. top: 50%;
  12. left: 50%;
  13. margin: -300px 0 0 -290px;
  14. border: 2px dotted pink;
  15. border-radius: 5px;
  16. }
  17. .register form {
  18. display: grid;
  19. gap: 1em;
  20. }
  21. .register form fieldset {
  22. display: grid;
  23. gap: 0.8em;
  24. }
  25. .register form > div:last-of-type {
  26. margin-top: 20px;
  27. display: flex;
  28. justify-content: space-around;
  29. }
  1. <div class="register">
  2. <form action="register.php" method="GET">
  3. <fieldset>
  4. <legend>必填项</legend>
  5. <div>
  6. <label for="account">用户名:</label>
  7. <input type="text" id="account" name="account" placeholder="用户名不得小于 3 个字符" required autofocus />
  8. </div>
  9. <div>
  10. <label for="password">密码:</label>
  11. <input type="password" id="password" name="password" placeholder="输入不少于8个字符的密码" required />
  12. <button type="button" onclick="document.querySelector('#password').type='text'">显示密码</button>
  13. </div>
  14. <div>
  15. <label for="pswConfirm">确认密码:</label>
  16. <input type="password" id="pswConfirm" name="pswConfirm" placeholder="重复输入密码" required />
  17. <button type="button" onclick="document.querySelector('#pswConfirm').type='text'">显示密码</button>
  18. </div>
  19. <div>
  20. <label for="email">邮箱:</label>
  21. <input type="email" id="email" name="email" placeholder="admin@mail.com" required />
  22. </div>
  23. </fieldset>
  24. <!-- 单选按钮 -->
  25. <div>
  26. <label for="secret">性别:</label>
  27. <input type="radio" name="gender" id="male" />
  28. <label for="male"></label>
  29. <input type="radio" name="gender" id="female" />
  30. <label for="female"></label>
  31. <input type="radio" name="gender" id="secret" />
  32. <label for="secret">保密</label>
  33. </div>
  34. <!-- 复选框 -->
  35. <div>
  36. <label for="">用户订阅</label>
  37. <input type="checkbox" name="subscribe[]" id="post" value="post" checked />
  38. <label for="post">公告</label>
  39. <input type="checkbox" name="subscribe[]" id="chat" value="chat" checked />
  40. <label for="chat">聊天吹水</label>
  41. <input type="checkbox" name="subscribe[]" id="game" value="game" />
  42. <label for="game">游戏攻略</label>
  43. <input type="checkbox" name="subscribe[]" id="movie" value="movie" />
  44. <label for="movie">影音视听</label>
  45. <input type="checkbox" name="subscribe[]" id="news" value="news" />
  46. <label for="news">小道资讯</label>
  47. <input type="checkbox" name="subscribe[]" id="other" value="other" />
  48. <label for="other">其他</label>
  49. </div>
  50. <!-- 下拉列表 -->
  51. <div>
  52. <label for="">密保问题</label>
  53. <select name="security" id="">
  54. <option value="sec">安全问题(未设置请忽略)</option>
  55. <option value="city">你出生的城市是?</option>
  56. <option value="birthday">你的生日是几号?</option>
  57. <option value="school">你毕业的大学是?</option>
  58. </select>
  59. </div>
  60. <!-- 搜索关键字 -->
  61. <div>
  62. <label for="">搜索关键词</label>
  63. <input type="search" name="search" list="keywords" />
  64. <datalist id="keywords">
  65. <option value="html">html</option>
  66. <option value="css">css</option>
  67. <option value="javascript">javascript</option>
  68. </datalist>
  69. </div>
  70. <div>
  71. <button>注册</button>
  72. <button type="reset">重置</button>
  73. </div>
  74. </form>
  75. </div>

效果预览:

(二)选择器权重的计算

  1. 选择器之间的优先级:
    !important > style > id > class > tag

2.id > class > tag 之间的组合应用

数值越大优先级越高,优先级高覆盖优先级低的。
为了便于理解,可将这三个标签看作百、十 、个位来进行计算。
以下面<h3>标签为例进行计算:

  1. <h3 id="a" class="b">权重选择器</h3>

样式1

  1. h3{
  2. background-color: red;
  3. }

样式2

  1. body h3 {
  2. background-color: blue;
  3. }

样式3

  1. .b{
  2. background-color: pink;
  3. }

样式4

  1. h3.b {
  2. background-color: green;
  3. }

样式5

  1. #a {
  2. background-color: green;
  3. }

计算过程及结果:

序号id/ 百class/ 十tag /个结果
1001001
2001+1002
3010010
4011011
5100100

(三)上下文选择器

  • 后代选择器(以空格 分隔)
  • 子元素选择器(以大于> 号分隔)
  • 相邻兄弟选择器(以加号+分隔)
  • 普通兄弟选择器(以波浪号分隔)
  1. <ul class="list">
  2. <li>item1</li>
  3. <li>item2</li>
  4. <li>
  5. item3
  6. <!-- <ul class="list2">
  7. <li>item3-1</li>
  8. <li>item3-2</li>
  9. <li>item3-3</li>
  10. </ul> -->
  11. </li>
  12. <li class="item">item4</li>
  13. <li>item5</li>
  14. <li>item6</li>
  15. <li>item7</li>
  16. <li>item8</li>
  17. </ul>
  18. <style>
  19. /* 子元素:>*/
  20. .list > li {
  21. border: 1px dashed blue;
  22. }
  23. /* 后代选择器:空格 */
  24. .list li {
  25. border: 1px dashed red;
  26. }
  27. /* 相邻选择器:+ 下一个 */
  28. .list .item + li {
  29. background-color: pink;
  30. }
  31. /* 兄弟选择器:~ */
  32. .list .item ~ * {
  33. background-color: cyan;
  34. }
  35. </style>

更多相关文章

  1. 注册表单选,择器权重的计算过程,上下文选择器
  2. HTML表单与选择器学习与应用
  3. CSS 元素样式来源
  4. html表单、元素的来源及csss外部样式和上下文选择器
  5. 尝试用css各类选择器添加样式制作一个注册表单
  6. 原生轮播图
  7. bootstrap的入门学习
  8. bootstrap常用组件样式使用之,导航,列表,按钮
  9. 第二十一课 Bootstrap学习

随机推荐

  1. 讲给前端的正则表达式(4):避免灾难性回溯[
  2. JS 和 Node.js 中的“事件驱动”是什么意
  3. 数组
  4. V8 引擎发布了 v8.0[每日前端夜话0x103]
  5. 离线安装veeam agent
  6. 栈的实现
  7. Java 中有哪些无锁技术来解决并发问题?如
  8. 如何解决Renault Can Clip代码不正确的问
  9. 什么是 Java 内存模型?
  10. FastAPI基础之Http状态码备忘