Blogger Information
Blog 13
fans 0
comment 0
visits 9770
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
Form注册表单 选择器权重计算及上下文选择器
樱风醉
Original
428 people have browsed it

(一)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 /个 结果
1 0 0 1 001
2 0 0 1+1 002
3 0 1 0 010
4 0 1 1 011
5 1 0 0 100

(三)上下文选择器

  • 后代选择器(以空格 分隔)
  • 子元素选择器(以大于> 号分隔)
  • 相邻兄弟选择器(以加号+分隔)
  • 普通兄弟选择器(以波浪号分隔)
  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>

Correcting teacher:PHPzPHPz

Correction status:qualified

Teacher's comments:不错
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!