久久久久久久视色,久久电影免费精品,中文亚洲欧美乱码在线观看,在线免费播放AV片

<center id="vfaef"><input id="vfaef"><table id="vfaef"></table></input></center>

    <p id="vfaef"><kbd id="vfaef"></kbd></p>

    
    
    <pre id="vfaef"><u id="vfaef"></u></pre>

      <thead id="vfaef"><input id="vfaef"></input></thead>

    1. 站長資訊網(wǎng)
      最全最豐富的資訊網(wǎng)站

      CSS3中background-clip實(shí)現(xiàn)圖片裁切3種效果(代碼實(shí)例 )

      本文目標(biāo):

      1、掌握background-clip背景裁切的3種實(shí)現(xiàn)

      問題:

      要求實(shí)現(xiàn)以下效果,使用純DIV+CSS,必須使用background-clip

      CSS3中background-clip實(shí)現(xiàn)圖片裁切3種效果(代碼實(shí)例 )

      附加說明:

      1、相框?qū)挾葹?00px,高500px,其中border寬20px,里面文字padding為20,邊框的大小為20px

      2、里面的圖片是當(dāng)做div的背景圖片使用

      現(xiàn)在來具體操作

      1、準(zhǔn)備素材:根目錄創(chuàng)建images文件夾,把相關(guān)素材圖片都存放與此,素材有

      CSS3中background-clip實(shí)現(xiàn)圖片裁切3種效果(代碼實(shí)例 )

      2、創(chuàng)建好index.html,寫好架構(gòu),架構(gòu)如何分析呢

      思路分析:

      1、目標(biāo)分成上下3部分,每個(gè)部分其實(shí)都是顯示一張同樣照片,所以只要第一個(gè)照片按照要求實(shí)現(xiàn)完成了,其他幾個(gè)都是可以復(fù)制

      2、但是仔細(xì)觀察,每張照片的顯示還是有所不同,我們發(fā)現(xiàn)第二張照片其實(shí)是在第一張照片的基礎(chǔ)上進(jìn)行裁切,裁切的大小恰恰是邊框的大小,相當(dāng)于裁切了邊框,而第三張的照片是在第二張照片的基礎(chǔ)上又進(jìn)行了裁切,裁切的大小又恰恰是里面padding的大小,也就是說第三張圖片是拆掉了內(nèi)容以外的部分,這就包括padding部分和邊框

      3、一個(gè)部分就是一個(gè)塊元素div,帶一個(gè)標(biāo)題,然后有邊框,有padding,有內(nèi)容字符串,最后帶一張背景圖

      根據(jù)分析,我們得出以下代碼

      <!DOCTYPE html> <html> <head>     <meta charset="utf-8">     <title>背景裁切案例演示</title> </head>  <body>     <div class="container">         <!-- 裁切效果一 -->         <h4>裁切效果一</h4>         <div class="photo  clip1">             <div class="content">周慧敏,微微一笑,很傾城</div>         </div>         <h4>裁切效果二</h4>         <div class="photo  clip2">             <div class="content">周慧敏,微微一笑,很傾城</div>         </div>         <h4>裁切效果三</h4>         <div class="photo  clip3">             <div class="content">周慧敏,微微一笑,很傾城</div>         </div>     </div> </body> </html>

      3、寫樣式 ,創(chuàng)建css文件夾,里面新建index.css,里面的樣式怎么寫了,以下是分析思路

      思路分析:

      1、.container *

      思路分析

      1、為了設(shè)置容器里的所有元素的公共樣式,我們可以將這些公共代碼寫入.container * 樣式內(nèi)

      所以index.css中添加代碼如下:

      .container *{     padding:0;     margin:0; }

      2、.photo照片

      思路分析

      1、根據(jù)要求得知,邊框20px,虛線顯示,轉(zhuǎn)成代碼即border-width:20px;border-style: dashed;里面的文字有間距,所以padding:20px,字體加粗font-weight:bold,顏色為白色color:#fff;

      寬度總體是500,所以width=500-(2個(gè)邊框20+20+2個(gè)padding20+20)=420,高度也是420,所以width:420,height:420

      2、因?yàn)檫@張照片的邊框是暗紅色的,所以border-color: indianred;然后背景是美女的照片,然后從效果可以看出虛線之間的顏色為灰色即#ccc,所以 background:#ccc url(../images/zhm.png) no-repeat;
      最關(guān)鍵的是,它的背景圖片是以border為起點(diǎn)的,所以background-origin: border-box;只不過每張照片的裁切點(diǎn)不同,但是這里我們可以把照片的共同屬性定義在此

      所以index.css中添加代碼如下:

      .photo {     width:420px;      height: 420px;     border-width:20px;     border-style:dashed;     padding:20px;      font-weight:bold;      color:#fff;      background:#ccc url(../images/zhm.png) no-repeat;      border-color: indianred;     background-origin: border-box; }

      3、3種不同的裁切方式

      1、第一種裁切方式是以邊框?yàn)槠瘘c(diǎn)進(jìn)行裁切邊框以外的部分,所以background-clip: border-box;

      2、第二種裁切方式是以padding為起點(diǎn)進(jìn)行裁切padding以外的部分,所以background-clip: padding-box;

      3、第三種裁切方式是以content為起點(diǎn)進(jìn)行裁切content外的部分,所以background-clip: content-box;
      所以index.css中添加代碼如下:

      .clip1{     background-clip: border-box; } .clip2{     background-clip: padding-box; } .clip3{     background-clip: content-box; }

      到此為止,index.css的全部內(nèi)容如下:

      .container *{     padding:0;     margin:0; } .photo {     width:420px;      height: 420px;     border-width:20px;     border-style:dashed;     padding:20px;      font-weight:bold;      color:#fff;      background:#ccc url(../images/zhm.png) no-repeat;      border-color: indianred;     background-origin: border-box; }  .clip1{     background-clip: border-box; } .clip2{     background-clip: padding-box; } .clip3{     background-clip: content-box; }

      然后將index.css引入index.html中

      <!DOCTYPE html> <html> <head>     <meta charset="utf-8">     <title>背景裁切案例演示</title>     <link rel="stylesheet" href="css/index.css" /> </head>  <body>     <div class="container">         <!-- 裁切效果一 -->         <h4>裁切效果一</h4>         <div class="photo  clip1">             <div class="content">周慧敏,微微一笑,很傾城</div>         </div>         <h4>裁切效果二</h4>         <div class="photo  clip2">             <div class="content">周慧敏,微微一笑,很傾城</div>         </div>         <h4>裁切效果三</h4>         <div class="photo  clip3">             <div class="content">周慧敏,微微一笑,很傾城</div>         </div>     </div> </body> </html>

      運(yùn)行結(jié)果如下:

      CSS3中background-clip實(shí)現(xiàn)圖片裁切3種效果(代碼實(shí)例 )

      到此為止,我們就實(shí)現(xiàn)了全部的需求

      總結(jié):

      1、學(xué)習(xí)了背景裁切的3種方式,語法格式是

      background-clip: border-box | padding-box | content-box | no-clip

      border-box:表示以邊框?yàn)槠瘘c(diǎn),裁切邊框外的部分

      padding-box:表示以padding為起點(diǎn),裁切padding外的部分

      content-box:表示以content為起點(diǎn),裁切content外的部分

      贊(0)
      分享到: 更多 (0)
      ?
      網(wǎng)站地圖   滬ICP備18035694號(hào)-2    滬公網(wǎng)安備31011702889846號(hào)