选择器id、class、tag

class>tag" class="reference-link">优先级id>class>tag

示例

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Document</title>
  6. <style type="text/css">
  7. /* id选择器,优先级大于class与tag,h1为红色*/
  8. h1#p11.p1{color: red}
  9. h1.p1{color: blue}
  10. h1{color: green}
  11. /* class选择器,优先级大于tag,h2为蓝色*/
  12. h2.p2{color: blue}
  13. h2{color: green}
  14. /* h3为绿色*/
  15. h2{color: green}
  16. </style>
  17. </head>
  18. <body>
  19. <h1 class="p1" id="p11">77777</h1>
  20. <h2 class="p2" id="p22">77777</h2>
  21. <h2 class="p3" id="p33">77777</h2>
  22. </body>
  23. </html>

效果如图

简单的前端组件样式模块化

dome.html

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Document</title>
  6. <!--引入文件index.css-->
  7. <link rel="stylesheet" type="text/css" href="css/index.css">
  8. </head>
  9. <body>
  10. <header></header>
  11. <main></main>
  12. <footer></footer>
  13. </body>
  14. </html>

index.css

  1. @import url(header.css);
  2. @import url(main.css);
  3. @import url(footer.css);

header.css

  1. header{min-height: 3em;background-color: red;}

main.css

  1. nain{min-height: 5em;background-color: blue;}
  1. footer{min-height: 4em;background-color: green;}

伪类选择器的使用

deom.html

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Document</title>
  6. <link rel="stylesheet" type="text/css" href="css/css.css">
  7. </head>
  8. <body>
  9. <ul class="list">
  10. <li>7777</li>
  11. <li>7777</li>
  12. <li>7777</li>
  13. <li>7777</li>
  14. <li>7777</li>
  15. <li>7777</li>
  16. </ul>
  17. <ul>
  18. <li>888</li>
  19. </ul>
  20. </body>
  21. </html>

css.css

  1. /*第一个li*/
  2. .list > li:first-of-type {
  3. background-color: red;
  4. }
  5. /*第二个li*/
  6. .list > li:nth-of-type(2) {
  7. background-color: yellow;
  8. }
  9. /*最后一个li*/
  10. .list>li:last-of-type{
  11. background-color: blue;
  12. }
  13. /*倒数第三个li*/
  14. .list>li:nth-last-of-type(3){
  15. background-color: green;
  16. }
  17. li:only-of-type{
  18. background-color: skyblue;
  19. }

效果如图

更多相关文章

  1. 选择器优先级/前端组件样式模块化原理与实现/常用伪类选择器的使
  2. 0322作业
  3. css基础、选择器、模块化组件
  4. 【CSS入门】CSS基本语法和选择器优先级学习总结简介
  5. 伪类选择器,优先级,模块化
  6. CSS选择器优先级、模块化与伪类选择器的原理及应用
  7. 选择器的优先级,id,class,tag
  8. CSS选择器优先级+模块化+伪类选择器
  9. python基本语法三

随机推荐

  1. Spring IoC 依赖注入的实现方式
  2. CCNP(ISCW)实验:使用SDM配置Site-to-Site
  3. IDEA最新激活码2021(IDEA2020.3永久激活方
  4. 一文读懂 SuperEdge 边缘容器架构与原理
  5. CCNP(ISCW)实验:使用SDM配置路由器
  6. 循环链表(单双链表)
  7. Android的View组件的几大子类
  8. 一篇文章教会你搭建自己的linux虚拟机
  9. Zabbix5.0服务端和客户端安装
  10. MySQL 百万级数据分页查询及优化