Blogger Information
Blog 7
fans 0
comment 0
visits 2817
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
选择器的认识和实战
风残念北的博客
Original
512 people have browsed it

1.选择器

1.1基本选择器

1.1.1标签选择器

  1. <!DOCTYPE html>
  2. <html lang="zh-CN">
  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>标签选择器</title>
  8. <link rel="stylesheet" href="./style.css">
  9. </head>
  10. <body>
  11. <h1>PHP中文网</h1>
  12. </body>
  13. </html>
  1. h1 {
  2. color: red;
  3. }

1.1.2属性选择器

代码演示

  1. <!DOCTYPE html>
  2. <html lang="zh-CN">
  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>属性选择器</title>
  8. <link rel="stylesheet" href="./style.css">
  9. </head>
  10. <body>
  11. <h1 class="title">PHP中文网</h1>
  12. <h2 id="name">Hello World</h2>
  13. </body>
  14. </html>
  1. h1.title {
  2. color: red ;
  3. }
  4. h2#name {
  5. color:blue;
  6. }

效果展示

属性选择器

1.2伪类选择器

1.2.1结构伪类

  1. <!DOCTYPE html>
  2. <html lang="zh-CN">
  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>伪类结构选择器</title>
  8. <link rel="stylesheet" href="./selecter.css">
  9. </head>
  10. <body>
  11. <ul class="list">
  12. <li>item1</li>
  13. <li>item2</li>
  14. <li>item3</li>
  15. <li>item4</li>
  16. <li>item5</li>
  17. <li>item6</li>
  18. <li>item7</li>
  19. <li>item8</li>
  20. <li>item9</li>
  21. </ul>
  22. </body>
  23. </html>

css代码段

  1. .list > :nth-child(3){
  2. color: red;
  3. }
  4. /* 第一个 */
  5. .list :first-child{
  6. color: blue;
  7. }
  8. /* 最后一个 */
  9. .list > :last-child{
  10. color: lightgreen;
  11. }
  12. /* 偶数改变颜色,利用2n */
  13. .list > :nth-child(2n){
  14. color: lightpink;
  15. }

效果展示

伪类结构选择器

1.2.2状态伪类

代码演示

  1. <!DOCTYPE html>
  2. <html lang="zh-CN">
  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>状态伪类</title>
  8. <link rel="stylesheet" href="fake-status.css">
  9. </head>
  10. <body>
  11. <form action="login.php" method="post">
  12. <fieldset style="width: 180px;">
  13. <legend>用户登录</legend>
  14. <input type="text" name="username" id="username" placeholder="请输入用户名">
  15. <input type="password" name="password" id="password" placeholder="请输入密码">
  16. <div>
  17. <input type="checkbox" name="remember" id="remember">
  18. <label for="remember">记住我</label>
  19. </div>
  20. <button>登录</button>
  21. </fieldset>
  22. </form>
  23. </body>
  24. </html>

css代码

  1. /* 获取到焦点时对背景颜色进行改变 */
  2. fieldset :focus{
  3. background-color: green;
  4. }
  5. /* 改变鼠标样式 */
  6. fieldset :hover{
  7. cursor: pointer;
  8. }
  9. /* 点击记住我改变label颜色 */
  10. input[type='checkbox']:checked + label{
  11. color: red;
  12. }

效果展示

1.3下拉菜单

  1. <!DOCTYPE html>
  2. <html lang="zh-CN">
  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>下拉菜单(状态伪类)</title>
  8. <link rel="stylesheet" href="./04.css">
  9. </head>
  10. <body>
  11. <div class="box">
  12. <label for="menu">城市列表</label>
  13. <input type="checkbox" name="city" id="menu">
  14. <ul>
  15. <li><a href="">博乐市</a></li>
  16. <li><a href="">上海市</a></li>
  17. <li><a href="">深圳市</a></li>
  18. </ul>
  19. </div>
  20. </body>
  21. </html>

css代码

  1. #menu {
  2. display: none;
  3. }
  4. #menu:checked + ul{
  5. display: none;
  6. }

1.3.1效果展示

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!