亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

搜索
博主信息
博文 11
粉絲 0
評(píng)論 0
訪問量 17191
最新下載
更多>
網(wǎng)站特效
網(wǎng)站源碼
網(wǎng)站素材
前端模板
CSS背景屬性、精靈圖和字體圖標(biāo)引用流程
Blueprint
原創(chuàng)
1647人瀏覽過

背景常用屬性

先來個(gè)概述圖:

color(顏色)

  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>Document</title>
  7. <style>
  8. div {
  9. /* 設(shè)定div大小 */
  10. width: 200px;
  11. height: 200px;
  12. /* 邊框線方便演示 */
  13. border: 1px dashed black;
  14. float: left;
  15. }
  16. .box {
  17. /* 背景顏色:16進(jìn)制 */
  18. background-color: #eee;
  19. }
  20. .box2 {
  21. /* 背景顏色:rgb */
  22. background-color: rgb(109, 109, 109);
  23. }
  24. .box3 {
  25. /* 背景顏色:單詞 */
  26. background-color: gray;
  27. }
  28. .box4 {
  29. /* 背景顏色:rgba */
  30. background-color: rgb(109, 109, 109,0.5) ;/*其中a代表透明度*/
  31. }
  32. </style>
  33. </head>
  34. <body>
  35. <div class="box">box</div>
  36. <div class="box2">box2</div>
  37. <div class="box3">box3</div>
  38. <div class="box4">box4</div>
  39. </body>
  40. </html>

image(背景圖片)和repeat(重復(fù)性)

背景默認(rèn)顯示方式:垂水平直平鋪

No-repeat:不重復(fù)

Repeat-x:水平平鋪

Repeat-y:垂直重復(fù)

  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>Document</title>
  7. <style>
  8. div {
  9. /* 設(shè)定div大小 */
  10. width: 600px;
  11. height: 600px;
  12. /* 邊框線方便演示 */
  13. border: 1px dashed black;
  14. float: left;
  15. margin: 0 20px;
  16. }
  17. .box {
  18. /* 圖片地址可以為本地圖片和網(wǎng)絡(luò)地址 */
  19. /* 背景默認(rèn)顯示方式,水平垂直平鋪 */
  20. background-image: url("1.jpeg");
  21. }
  22. .box2 {
  23. /* 不重復(fù) */
  24. background-image: url("1.jpeg");
  25. background-repeat: no-repeat;
  26. }
  27. .box3 {
  28. /* 水平平鋪 */
  29. background-image: url("1.jpeg");
  30. background-repeat: repeat-x;
  31. }
  32. .box4 {
  33. /* 垂直平鋪 */
  34. background-image: url("1.jpeg");
  35. background-repeat: repeat-y;
  36. }
  37. </style>
  38. </head>
  39. <body>
  40. <div class="box">box</div>
  41. <div class="box2">box2</div>
  42. <div class="box3">box3</div>
  43. <div class="box4">box4</div>
  44. </body>
  45. </html>

sizing(大小)

屬性值cover 寬和高較高值得比例縮放 會(huì)破壞圖片的顯示效果

屬性值contain 寬和高較低值得比例縮放 不會(huì)破壞圖片的顯示效果

  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>Document</title>
  7. <style>
  8. div {
  9. /* 設(shè)定div大小 */
  10. width: 600px;
  11. height: 800px;
  12. /* 邊框線方便演示 */
  13. border: 1px dashed black;
  14. float: left;
  15. margin: 0 20px;
  16. }
  17. .box1 {
  18. /* 導(dǎo)入圖片 */
  19. background-image: url("1.jpeg");
  20. /* 設(shè)置不重復(fù) */
  21. background-repeat: no-repeat;
  22. /* 屬性值contain 寬和高較低值得比例縮放 不會(huì)破壞圖片的顯示效果*/
  23. background-size: contain;
  24. }
  25. .box2 {
  26. /* 導(dǎo)入圖片 */
  27. background-image: url("1.jpeg");
  28. /* 設(shè)置不重復(fù) */
  29. background-repeat: no-repeat;
  30. /* 屬性值cover 寬和高較高值得比例縮放 會(huì)破壞圖片的顯示效果*/
  31. background-size: cover;
  32. }
  33. .box3 {
  34. /* 導(dǎo)入圖片 */
  35. background-image: url("1.jpeg");
  36. /* 設(shè)置不重復(fù) */
  37. background-repeat: no-repeat;
  38. /* 數(shù)值 */
  39. background-size: 200px 200px;
  40. }
  41. .box4 {
  42. /* 導(dǎo)入圖片 */
  43. background-image: url("1.jpeg");
  44. /* 設(shè)置不重復(fù) */
  45. background-repeat: no-repeat;
  46. /* 百分百 */
  47. background-size: 20% 20%;
  48. }
  49. </style>
  50. </head>
  51. <body>
  52. <div class="box1">box1</div>
  53. <div class="box2">box2</div>
  54. <div class="box3">box2</div>
  55. <div class="box4">box2</div>
  56. </body>
  57. </html>

position(定位)

數(shù)值定位是,屬性值是有順序的

屬性值只有一個(gè),第二個(gè)默認(rèn)center

  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>Document</title>
  7. <style>
  8. div {
  9. width: 800px;
  10. height: 1000px;
  11. border: 1px dashed red;
  12. float: left;
  13. /* 導(dǎo)入圖片 */
  14. background-image: url('1.jpeg');
  15. /* 防止重復(fù) */
  16. background-repeat: no-repeat;
  17. }
  18. .box1{
  19. /* 數(shù)值定位,水平/垂直 有順序 */
  20. background-position: 100px ;
  21. }
  22. .box2{
  23. /* 方位定位,無順序要求 */
  24. background-position: center left;
  25. }
  26. .box3{
  27. /* 方位定位,無順序要求 */
  28. background-position: 100% 20%;
  29. }
  30. /* 定位時(shí),單個(gè)值,第二個(gè)值默認(rèn)center */
  31. </style>
  32. </head>
  33. <body>
  34. <div class="box1"></div>
  35. <div class="box2"></div>
  36. <div class="box3"></div>
  37. </body>
  38. </html>

背景固定

使用fixed屬性值時(shí),圖片脫離原有的位置,可以使用定位。

  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>Document</title>
  7. </head>
  8. <style>
  9. body > * {
  10. float: left;
  11. border: 1px dashed red;
  12. margin: 0 100px;
  13. }
  14. .box1,
  15. .box2 {
  16. width: 600px;
  17. height: 600px;
  18. overflow: scroll;
  19. }
  20. .box3,
  21. .box4 {
  22. width: 256px;
  23. height: 600%;
  24. background-repeat: no-repeat;
  25. background-image: url("1.jpeg");
  26. }
  27. .box3 {
  28. /* 固定背景 */
  29. background-attachment: fixed;
  30. /* 定位背景位置 */
  31. background-position: 120px 20px;
  32. }
  33. .box4 {
  34. /* 背景不固定默認(rèn)值*/
  35. background-attachment: scroll;
  36. }
  37. </style>
  38. <body>
  39. <div class="box1">
  40. <div class="box3"></div>
  41. </div>
  42. <div class="box2">
  43. <div class="box4"></div>
  44. </div>
  45. </body>
  46. </html>

簡(jiǎn)寫屬性

background:顏色 圖片 重復(fù) 固定 定位;

同時(shí)擁有顏色和圖片時(shí), 圖片會(huì)覆蓋顏色

  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>Document</title>
  7. </head>
  8. <style>
  9. div {
  10. width: 500px;
  11. height: 500px;
  12. border: 1px dashed red;
  13. /* 屬性簡(jiǎn)寫 */
  14. background: #ccc url("1.jpeg") no-repeat scroll 100px 20px;
  15. }
  16. </style>
  17. <body>
  18. <div></div>
  19. </body>
  20. </html>

精靈圖

什么是精靈圖:

css精靈(CSS sprites),是一種網(wǎng)頁(yè)圖片應(yīng)用處理技術(shù)。主要是指將網(wǎng)頁(yè)中需要的零星的小圖片集成到一個(gè)大的圖片中

應(yīng)用的原因:

  1. 減少對(duì)瀏覽器的請(qǐng)求次數(shù),避免網(wǎng)頁(yè)的延遲
  2. 方便小圖標(biāo)的統(tǒng)一管理

精靈圖的使用: css精靈圖需要配合背景的圖片和背景定位

  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>Document</title>
  7. <style>
  8. .box {
  9. width: 960px;
  10. height: 500px;
  11. border: 1px solid black;
  12. clear: both;
  13. }
  14. .box > *:not(img) {
  15. width: 100px;
  16. height: 100px;
  17. border: 1px dashed red;
  18. float: left;
  19. }
  20. .box1 {
  21. /* 導(dǎo)入圖片 */
  22. background-image: url("1.png");
  23. /* 定位背景獲取精靈圖上需要的部分圖片 */
  24. background-position: 0px -30px;
  25. }
  26. .box2 {
  27. /* 導(dǎo)入圖片 */
  28. background-image: url("1.png");
  29. /* 定位背景獲取精靈圖上需要的部分圖片 */
  30. background-position: 100px -30px;
  31. }
  32. .box3 {
  33. /* 導(dǎo)入圖片 */
  34. background-image: url("1.png");
  35. /* 定位背景獲取精靈圖上需要的部分圖片 */
  36. background-position: -90px -120px;
  37. }
  38. .box4 {
  39. /* 導(dǎo)入圖片 */
  40. background-image: url("1.png");
  41. /* 定位背景獲取精靈圖上需要的部分圖片 */
  42. background-position: -275px -210px;
  43. }
  44. .box5 {
  45. /* 導(dǎo)入圖片 */
  46. background-image: url("1.png");
  47. /* 定位背景獲取精靈圖上需要的部分圖片 */
  48. background-position: 0px -30px;
  49. }
  50. </style>
  51. </head>
  52. <body>
  53. <div class="box">
  54. <div class="box1"></div>
  55. <div class="box2"></div>
  56. <div class="box3"></div>
  57. <div class="box4"></div>
  58. <div class="box5"></div>
  59. <img src="1.png" alt="" />
  60. </div>
  61. </body>
  62. </html>

字體圖標(biāo)

眾所周知,單位字體的文件大小小于圖片的大小,考慮精靈圖處理的是一張張圖片,有人就有了一個(gè)奇思妙想—把圖片轉(zhuǎn)換成字體(實(shí)際上字體本來就是那么設(shè)計(jì)下來的。)

轉(zhuǎn)換成字體后,可以使用特殊的代碼來顯示出指定的圖片。

字體圖標(biāo)比精靈圖有一個(gè)非常明顯的好處,因?yàn)樗亲煮w,所以它能夠改變字體顏色,能改變字體大?。ú⑶也粫?huì)失真)。

例子:

僅演示字體圖標(biāo)的使用

1.獲取字體圖標(biāo)

iconfont(下面演示使用)

Font Awesome

IconMonstr

IconShock·····

? 多圖演示獲取步驟:


將下載的壓縮包解壓獲取文件夾,并將壓縮包下的所有文件移動(dòng)到項(xiàng)目(也可將文件夾拖至項(xiàng)目,保證項(xiàng)目的目錄層次)

  1. 字體引用

    第一步:引入項(xiàng)目下面生成的 fontclass 代碼:

  1. <link rel="stylesheet" href="./iconfont.css">

第二步:挑選相應(yīng)圖標(biāo)并獲取類名,應(yīng)用于頁(yè)面:

  1. <span class="iconfont icon-xxx"></span>

批改老師:WJWJ

批改狀態(tài):合格

老師批語(yǔ):總得來說寫的不錯(cuò)很認(rèn)真,不要重復(fù)提交!
本博文版權(quán)歸博主所有,轉(zhuǎn)載請(qǐng)注明地址!如有侵權(quán)、違法,請(qǐng)聯(lián)系admin@php.cn舉報(bào)處理!
全部評(píng)論 文明上網(wǎng)理性發(fā)言,請(qǐng)遵守新聞評(píng)論服務(wù)協(xié)議
0條評(píng)論
作者最新博文
關(guān)于我們 免責(zé)申明 意見反饋 講師合作 廣告合作 最新更新
php中文網(wǎng):公益在線php培訓(xùn),幫助PHP學(xué)習(xí)者快速成長(zhǎng)!
關(guān)注服務(wù)號(hào) 技術(shù)交流群
PHP中文網(wǎng)訂閱號(hào)
每天精選資源文章推送
PHP中文網(wǎng)APP
隨時(shí)隨地碎片化學(xué)習(xí)
PHP中文網(wǎng)抖音號(hào)
發(fā)現(xiàn)有趣的

Copyright 2014-2025 http://ipnx.cn/ All Rights Reserved | php.cn | 湘ICP備2023035733號(hào)

  • 登錄PHP中文網(wǎng),和優(yōu)秀的人一起學(xué)習(xí)!
    全站2000+教程免費(fèi)學(xué)