伪类选择器

  1. <ol class="olist">
  2. <li>item1</li>
  3. <li>item2</li>
  4. <ul class="ulist">
  5. <li>item1</li>
  6. <li>item2</li>
  7. <li>item3</li>
  8. <li>item4</li>
  9. <li>item5</li>
  10. <li>item6</li>
  11. <li>item7</li>
  12. <li>item8</li>
  13. <li>item9</li>
  14. <li>item10</li>
  15. </ul>
  16. <li>item3</li>
  17. <li>item4</li>
  18. <li>item5</li>
  19. </ol>
  20. <style>
  21. /* 第5个子元素 */
  22. .olist > li:nth-child(5) {
  23. color: red;
  24. }
  25. /* 第1个元素 */
  26. .olist > li:first-of-type {
  27. color: salmon;
  28. }
  29. /* 最后1个元素 */
  30. .olist > li:last-of-type {
  31. color: saddlebrown;
  32. }
  33. /* 奇数项 */
  34. .ulist > li:nth-of-type(odd) {
  35. color: seagreen;
  36. }
  37. /* 偶数项 */
  38. .ulist > li:nth-of-type(even) {
  39. color: aquamarine;
  40. }
  41. /* 3,6,9行 */
  42. .ulist > li:nth-of-type(3n) {
  43. font-weight: bold;
  44. }
  45. /* 第4行 */
  46. .ulist > li:nth-of-type(4) {
  47. font-style: italic;
  48. }
  49. /* 公式 an+b
  50. a:一个循环的大小
  51. n:计数器,从0开始
  52. b:偏移量 */
  53. /* 1,4,7,10 */
  54. .ulist > li:nth-of-type(3n + 1) {
  55. color: blue;
  56. font-size: xx-large;
  57. }
  58. /* 倒数第2个元素 */
  59. .ulist > li:nth-last-of-type(2) {
  60. color: gold;
  61. }
  62. </style>
  63. <!-- 表单伪类 -->
  64. <div>
  65. <input type="radio" name="sex" value="0" id="m" /><label for="m"
  66. ></label
  67. >
  68. <input type="radio" name="sex" value="1" id="f" /><label for="f"
  69. ></label
  70. >
  71. </div>
  72. <input type="text" class="te" />
  73. <button>按钮</button>
  74. <style>
  75. input:checked + label {
  76. color: red;
  77. }
  78. button:hover {
  79. background-color: indianred;
  80. color: white;
  81. cursor: pointer;
  82. }
  83. .te:focus {
  84. background-color: gold;
  85. }
  86. </style>

图示:
图示


字体图标

第一步:登录 https://www.iconfont.cn/ 下载字体图标。
第二步:将压缩包解压,放到项目里。
第三步:打开压缩包中的 demo_index.html 查看使用说明。
第四步:按照使用说明添加引入代码。
第五步:用css控制引入的字体图标。

  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>Document</title>
  8. <!-- 引入字体图标css -->
  9. <link rel="stylesheet" href="./font_icon/iconfont.css" />
  10. </head>
  11. <body>
  12. <!-- 插入图标 -->
  13. <p><span class="iconfont icon-arrow-left"></span></p>
  14. <!-- 用css控制字体图标 -->
  15. <style>
  16. .icon-arrow-left {
  17. color: red;
  18. font-size: xx-large;
  19. }
  20. </style>
  21. </body>
  22. </html>

盒模型

常用属性:width,height,border,padding,margin

  1. <div class="box1"></div>
  2. <div class="box2"></div>
  3. <style>
  4. .box1,
  5. .box2 {
  6. width: 200px;
  7. height: 200px;
  8. border: 10px dashed red;
  9. background-color: tan;
  10. /* 剪裁背景 */
  11. background-clip: content-box;
  12. /* 内边距 */
  13. padding: 5px 10px 15px 20px;
  14. /* 外边距 */
  15. margin: 5px 10px 15px 20px;
  16. /* 此时, width, heigth设置的盒子大小, 就是最终的计算尺寸 */
  17. box-sizing: border-box;
  18. /* 边框样式可单独设置 */
  19. border-bottom: dotted;
  20. }
  21. </style>

图示:
图示


常用单位

绝对单位: px
相对单位:em rem vh vw
em:和自己或父对象的font-size绑定
rem:和html的font-size绑定
vh:视口高,用百分比
vw:视口宽,用百分比

em , rem

  1. <div class="box"></div>
  2. <div class="box1"></div>
  3. <style>
  4. html {
  5. font-size: 20px;
  6. }
  7. .box {
  8. font-size: 10px;
  9. width: 10em;
  10. height: 10em;
  11. background-color: slateblue;
  12. }
  13. .box1 {
  14. font-size: 10px;
  15. width: 10rem;
  16. height: 10rem;
  17. background-color: yellowgreen;
  18. }
  19. </style>

图示:
图示


vh vw

  1. <header></header>
  2. <aside class="left"></aside>
  3. <main></main>
  4. <aside class="right"></aside>
  5. <footer></footer>
  6. <style>
  7. * {
  8. padding: 0;
  9. margin: 0;
  10. box-sizing: border-box;
  11. }
  12. header,
  13. footer {
  14. background-color: burlywood;
  15. }
  16. main {
  17. background-color: dodgerblue;
  18. }
  19. .left,
  20. .right {
  21. background-color: darkgray;
  22. }
  23. body {
  24. display: grid;
  25. grid-template-rows: 10vh 80vh 10vh;
  26. grid-template-columns: 20vw 70vw 10vw;
  27. }
  28. header,
  29. footer {
  30. grid-column: span 3;
  31. }
  32. </style>

图示:
图示

更多相关文章

  1. Android(安卓)UI之ImageButton(带图标的按钮)
  2. AsyncTask实例代码演示Android异步任务
  3. Android菜单详解(三)——SubMenu和IconMenu
  4. Android实现图标水印
  5. Android聊天软件开发(基于网易云IM即时通讯)——添加好友(三)
  6. android 系统自带的图标集合
  7. android 状态栏显示运行图标
  8. Android获取apk的版本及包名等信息
  9. Android(安卓)获取设备电池电量

随机推荐

  1. spring实现java的邮件发送
  2. J2EE4层体系结构
  3. java 导出excel 格式与文件扩展名指定的
  4. 2016年团体程序设计天梯赛-初赛 - 重要的
  5. 打造Linux下vim之(一)vim中的JavaScript插
  6. java对象判断是否为空工具类
  7. ARM-LINUX 系列 (七) ----java的安装
  8. eclipse下,tomact jar包存在 但是无法解析
  9. 一个关于javascript压缩混淆工具的问题
  10. 百度Java架构师分享分布式锁的技术选型及