博主信息
博文 11
粉丝 0
评论 0
访问量 11170
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
网页背景、精灵图、阿里字体图标引用的初次体验
Haggi的糖果屋
原创
815人浏览过

一、网页背景控制

网页背景属性:

属性 说明
background-color 背景色
background-clip content-box
background: linear-gradient 渐变
background-image 背景图
background-repeat 重复
background-attachment 固定位置
background-position 定位
background-size 背景图大小样式

实例:
1.background-color:
代码:

  1. <style>
  2. .box {
  3. background-color: aqua;
  4. width: 300px;
  5. height: 300px;
  6. margin: auto;
  7. }
  8. </style>

运行图:

2.background-clip:
代码:

  1. <style>
  2. .box {
  3. background-color: aqua;
  4. width: 300px;
  5. height: 300px;
  6. margin: auto;
  7. background-clip: content-box;
  8. padding: 20px;
  9. border: 2px solid lightcoral;
  10. }
  11. </style>

运行图:

3.background: linear-gradient:
代码

  1. <style>
  2. .box {
  3. /* background-color: aqua; */
  4. width: 100px;
  5. height: 100px;
  6. margin: auto;
  7. /* background-clip: content-box;
  8. padding: 20px; */
  9. /* border: 2px solid lightcoral; */
  10. background: linear-gradient(red, yellow);
  11. }
  12. .box1 {
  13. background: linear-gradient(45deg, red, yellow, green);
  14. }
  15. .box2 {
  16. background: linear-gradient(to right, green, red, yellow);
  17. }
  18. .box3 {
  19. background: linear-gradient(
  20. to left,
  21. rgba(255, 0, 0, 0.1),
  22. rgba(0, 255, 0, 0.5)
  23. );
  24. }
  25. </style>

运行图:

4.background-image、background-repeat对比
代码:

  1. background-image: url("girl.jpg");
  2. background-repeat: no-repeat;

运行图:


5.background-attachment
代码:

  1. background-attachment: fixed;

运行图:

6.background-position

  1. <style>
  2. .box {
  3. width: 400px;
  4. height: 400px;
  5. margin: auto;
  6. border: 2px solid lightcoral;
  7. background-image: url("girl.jpg");
  8. background-repeat: no-repeat;
  9. background-position: center right;
  10. }
  11. .box1 {
  12. background-position: 50%;
  13. }
  14. .box2 {
  15. background-position: center left;
  16. }
  17. .box3 {
  18. background-position: 50px 50px;
  19. }

运行图:

6.background-size

  1. .box {
  2. width: 400px;
  3. height: 400px;
  4. margin: auto;
  5. background-size: cover;
  6. background-image: url("girl.jpg");
  7. }

运行图:


二、精灵图

精灵图能够减少获取图片次数的请求资源,浏览器只请求一次资源,无须多次请求。
举例代码:

  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. background-image: url("1.png");
  12. background-repeat: no-repeat;
  13. background-position: 50px 20px;
  14. }
  15. .box2 {
  16. width: 110px;
  17. height: 110px;
  18. float: left;
  19. background-image: url("1.png");
  20. background-repeat: no-repeat;
  21. background-position: -220px -110px;
  22. }
  23. .box3 {
  24. width: 110px;
  25. height: 110px;
  26. float: left;
  27. background-image: url("1.png");
  28. background-repeat: no-repeat;
  29. background-position: -220px -220px;
  30. }
  31. .box4 {
  32. width: 110px;
  33. height: 110px;
  34. float: left;
  35. background-image: url("1.png");
  36. background-repeat: no-repeat;
  37. background-position: 0 -220px;
  38. }
  39. </style>
  40. </head>
  41. <body>
  42. <div class="box1"></div>
  43. <div>
  44. <div class="box2"></div>
  45. <div class="box3"></div>
  46. <div class="box4"></div>
  47. </div>
  48. </body>
  49. </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. <!-- 引入字体图标的类样式 -->
  7. <link rel="stylesheet" href="font-class/iconfont.css" />
  8. <title>阿里字体图标的使用方法1</title>
  9. <style>
  10. .knock1 {
  11. font-size: 100px;
  12. color: coral;
  13. }
  14. .knock2 {
  15. font-size: 100px;
  16. color: red;
  17. }
  18. </style>
  19. </head>
  20. <body>
  21. <div>
  22. <span class="iconfont icon-dianzan1 knock1"></span>
  23. <span class="iconfont icon-dianzan2 knock2"></span>
  24. </div>
  25. </body>
  26. </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+教程免费学