博客列表 >背景控制的常用属性、精灵图的原理与实现、阿里字体图标的完整引用流程

背景控制的常用属性、精灵图的原理与实现、阿里字体图标的完整引用流程

浪子修罗记录有趣的事
浪子修罗记录有趣的事原创
2020年06月21日 22:35:35635浏览

背景控制的常用属性

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8" />
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  6. <title>背景</title>
  7. <style>
  8. .box {
  9. width: 500px;
  10. height: 500px;
  11. border: 1px solid black;
  12. /* 背景色 */
  13. background-color: lightgoldenrodyellow;
  14. /* padding: 20px; */
  15. /* 控制背景的覆盖范围限制在内容区,裁切 */
  16. background-color: border-box;
  17. background-color: content-box;
  18. /* 渐变 */
  19. /* 从上到下 */
  20. background: linear-gradient(red, yellow);
  21. /* 45度 */
  22. background: linear-gradient(45deg, red, yellow);
  23. /* 从右到左 */
  24. background: linear-gradient(to right, red, yellow);
  25. /* 从左到右的;四色渐变 */
  26. background: linear-gradient(to left, red, yellow, white, yellow);
  27. /* 背景图片 */
  28. background-image: url(girl.jpg);
  29. /* 背景不重复 */
  30. background-repeat: no-repeat;
  31. /* 滚动条 */
  32. /* background-attachment: fixed; */
  33. /* 背景定位:位置 */
  34. /* background-position: 80px 70px; */
  35. /* 当使用关键字的时候,顺序没有关系。如:left 等,只写一个时,第二个默认为center */
  36. /* background-position: right center; */
  37. /* 使用百分比的时候只有一个参数的时候,第二个也默认50% */
  38. /* background-position: 50% 20%; */
  39. /* 把图像图像扩展至最大尺寸,以使宽度和高度完全适应内容区域。 */
  40. background-size: contain;
  41. /* 把背景图像扩展至足够大,以使背景图像完全覆盖背景区域。背景图像的某些部分也许无法显示在背景定位区域中。 */
  42. background-size: cover;
  43. /* 简写 */
  44. background: url(girl.jpg) cover;
  45. /* 加阴影 */
  46. box-shadow: 5px 8px 6px #888;
  47. /* 圆角 */
  48. border-radius: 250px;
  49. }
  50. </style>
  51. </head>
  52. <body>
  53. <div class="box"></div>
  54. </body>
  55. </html>

精灵图的原理与实现

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8" />
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  6. <title>背景实战:精灵图/雪碧图</title>
  7. <style>
  8. .box1 {
  9. width: 500px;
  10. height: 400px;
  11. border: 1px solid #000;
  12. background-image: url("001.png");
  13. background-repeat: no-repeat;
  14. background-position: 20px 20px;
  15. }
  16. .box2 {
  17. /* 取灰色房子图标 宽和高需要设置为图标大小*/
  18. width: 110px;
  19. height: 110px;
  20. background-image: url("001.png");
  21. background-repeat: no-repeat;
  22. /* 设置x轴110px y轴为0 */
  23. background-position: -110px -1px;
  24. }
  25. .box2:hover {
  26. /* 取灰色房子图标 宽和高需要设置为图标大小*/
  27. width: 110px;
  28. height: 110px;
  29. background-image: url("001.png");
  30. background-repeat: no-repeat;
  31. /* 设置x轴110px y轴为0 */
  32. background-position: 0px -1px;
  33. }
  34. .box3 {
  35. /* 取橘黄色地球图标 宽和高需要设置为图标大小*/
  36. width: 110px;
  37. height: 110px;
  38. background-image: url("001.png");
  39. background-repeat: no-repeat;
  40. /* 设置x轴-220px y轴为-110 */
  41. background-position: -330px -220px;
  42. }
  43. .box3:hover {
  44. /* 取橘黄色地球图标 宽和高需要设置为图标大小*/
  45. width: 110px;
  46. height: 110px;
  47. background-image: url("001.png");
  48. background-repeat: no-repeat;
  49. /* 设置x轴-220px y轴为-110 */
  50. background-position: -220px -220px;
  51. }
  52. </style>
  53. </head>
  54. <body>
  55. <div class="box1"></div>
  56. <div class="box2"></div>
  57. <div class="box3"></div>
  58. </body>
  59. </html>

阿里字体图标的完整引用流程

font-class 引用

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8" />
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  6. <link rel="stylesheet" href="font/iconfont.css" />
  7. <title>阿里字体图标的使用方法1-font-class 引用</title>
  8. <style>
  9. .ico {
  10. font-size: 80px;
  11. color: brown;
  12. }
  13. </style>
  14. </head>
  15. <body>
  16. <span class="iconfont icon-taobao ico"></span>
  17. </body>
  18. </html>

Unicode 引用

deom4.html

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8" />
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  6. <link rel="stylesheet" href="css.css" />
  7. <title>阿里字体图标的使用方法2-Unicode 引用</title>
  8. <style>
  9. .ico {
  10. font-size: 50px;
  11. color: chartreuse;
  12. }
  13. </style>
  14. </head>
  15. <body>
  16. <span class="iconfont ico">&#xe683;</span>
  17. </body>
  18. </html>

css.css

  1. @font-face {
  2. font-family: "iconfont";
  3. src: url("font/iconfont.eot");
  4. src: url("font/iconfont.eot?#iefix") format("embedded-opentype"),
  5. url("font/iconfont.woff2") format("woff2"),
  6. url("font/iconfont.woff") format("woff"),
  7. url("font/iconfont.ttf") format("truetype"),
  8. url("font/iconfont.svg#iconfont") format("svg");
  9. }
  10. .iconfont {
  11. font-family: "iconfont" !important;
  12. font-size: 16px;
  13. font-style: normal;
  14. -webkit-font-smoothing: antialiased;
  15. -moz-osx-font-smoothing: grayscale;
  16. }
声明:本文内容转载自脚本之家,由网友自发贡献,版权归原作者所有,如您发现涉嫌抄袭侵权,请联系admin@php.cn 核实处理。
全部评论
文明上网理性发言,请遵守新闻评论服务协议