Blogger Information
Blog 62
fans 3
comment 1
visits 29941
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
CSS选择器中优先级和权重区别
kiraseo_wwwkiraercom
Original
318 people have browsed it

自定义样式的来源与优先级

  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>自定义样式的来源与优先级</title>
  8. <link rel="stylesheet" href="css/zuoye.css">
  9. </head>
  10. <body>
  11. <h2 style="color: red;" class="color" id="color">我是最高级内联样式</h2>
  12. <h2 class="color" id="color">我是外部样式class,但是只能优先显示id</h2>
  13. <h2 class="color">我只是为了演示class颜色而已</h2>
  14. <!-- 通过演示效果的优先级 -->
  15. <!-- 自定义样式优先级如下-->
  16. <!--内链式>id>class -->
  17. <!-- 内嵌式红色大于id 黄色 大于class蓝色-->
  18. </body>
  19. </html>
  1. <!-zuoye.css->
  2. .color{color: blue;}
  3. #color{color: yellow;}

实际页面演示

演示

常用选择器与权重分析方法

  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>常用选择器与权重分析方法</title>
  8. <link rel="stylesheet" href="css/zuoye2.css">
  9. </head>
  10. <body>
  11. <div>选择器</div>
  12. <ul class="list" id="nav">
  13. <li class="item">显示1</li>
  14. <li class="item">显示2</li>
  15. <li class="item">显示3</li>
  16. </ul>
  17. <!--权重分类id,class ,tag(标签) 三类 -->
  18. </body>
  19. </html>
  1. <!-zuoye2.css->
  2. /* 当前css 按照《选择权重》顺序书写*/
  3. #nav{background-color: yellow;}
  4. .list>.item{border: 1px solid red;}
  5. li{list-style: none;}

实际页面演示

演示

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