博主信息
博文 11
粉丝 0
评论 1
访问量 10326
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
CSS引入方式与选择器
一代宗师
原创
727人浏览过

CSS引入方式

  1. <html lang="en">
  2. <head>
  3. <meta charset="UTF-8">
  4. <title>CSS三种引入方式</title>
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <!--外部样式-->
  8. <link type="text/css" rel="stylesheet" href="style.css" />
  9. <!--内嵌样式-->
  10. <style>
  11. .head{
  12. width: 100px;
  13. height: 100px;
  14. }
  15. </style>
  16. </head>
  17. <body>
  18. <!--行内样式-->
  19. <p style="color:#F00; "></p>
  20. <div class="head"></div>
  21. <div></div>
  22. </body>
  23. </html>

选择器

  1. <html lang="en">
  2. <head>
  3. <meta charset="UTF-8">
  4. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>选择器</title>
  7. <style>
  8. p{color: darkmagenta;}
  9. .header{
  10. width: 1920px;
  11. }
  12. #main{
  13. width: 1920px;
  14. }
  15. /* 同级相邻选择器 */
  16. .str+li{color: deepskyblue;}
  17. /* 同级所有选择器 */
  18. .int~li{color: gold;}
  19. /* 后代选择器 */
  20. ul li{
  21. color: hotpink;
  22. }
  23. /* 子元素选择器 */
  24. body>ul>li{
  25. color: rgb(228, 51, 20);
  26. }
  27. </style>
  28. </head>
  29. <body>
  30. <p>标签选择器</p>
  31. <div class="header">class选择器</div>
  32. <div id="main"></div>
  33. <ul>
  34. <li>text1</li>
  35. <li class="str">text2</li>
  36. <li>text3</li>
  37. <ul>
  38. <li class="int">text4</li>
  39. <li>text5</li>
  40. <li>text6</li>
  41. </ul>
  42. </ul>
  43. </body>
  44. </html>

伪类选择器

  1. <html lang="en">
  2. <head>
  3. <meta charset="UTF-8">
  4. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>伪类选择器</title>
  7. <style>
  8. ul li:nth-of-type(3){
  9. color: hotpink;
  10. }
  11. ul li:nth-of-type(n){
  12. color: hotpink;
  13. }
  14. ul li:nth-of-type(2n){
  15. color: #000;
  16. }
  17. ul li:nth-of-type(2n+1){
  18. color: lawngreen;
  19. }
  20. ul li:nth-of-type(even){
  21. color: lightcoral;
  22. }
  23. ul li:nth-of-type(odd){
  24. color: lightgray;
  25. }
  26. ul li:first-of-type{color: mediumvioletred;}
  27. ul li:last-of-type{color: midnightblue;}
  28. ul li:nth-of-type(n+5){color: blue;}
  29. ul li:nth-last-of-type(-n+3){color: brown;}
  30. ul li:nth-last-of-type(4){color: rgb(243, 16, 84);}
  31. ul li:only-of-type{color: darkblue;}
  32. </style>
  33. </head>
  34. <body>
  35. <ul>
  36. <li>text1</li>
  37. <li>text2</li>
  38. <li>text3</li>
  39. <li>text4</li>
  40. <li>text5</li>
  41. <li>text6</li>
  42. <li>text7</li>
  43. <li>text8</li>
  44. <li>text9</li>
  45. </ul>
  46. <ul>
  47. <li>texts</li>
  48. </ul>
  49. </body>
  50. </html>
批改老师:天蓬老师天蓬老师

批改状态:合格

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

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

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