登录  /  注册
博主信息
博文 8
粉丝 0
评论 0
访问量 5236
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
css基础:简单的选择器、伪类选择器与前端组件样式模块化知识
WSC
原创
429人浏览过

选择器id、class、tag

优先级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. }

效果如图

批改老师:天蓬老师天蓬老师

批改状态:合格

老师批语:
本博文版权归博主所有,转载请注明地址!如有侵权、违法,请联系admin@php.cn举报处理!
全部评论 文明上网理性发言,请遵守新闻评论服务协议
0条评论
作者最新博文
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2024 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号

  • 登录PHP中文网,和优秀的人一起学习!
    全站2000+教程免费学