欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

css3遮罩層鏤空效果的多種實現(xiàn)方法

  發(fā)布時間:2020-05-11 16:06:25   作者:小麥   我要評論
這篇文章主要介紹了css3遮罩層鏤空效果的多種實現(xiàn)方法,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧

本文介紹了的4種實現(xiàn)遮罩層鏤空的方法,分享給大家,也給自己留個筆記,具體如下:

先看看效果

【 方法一:截圖模擬實現(xiàn) 】

原理:先截一張相同位置的圖片,創(chuàng)建一個遮罩層,然后把圖片定位在相應的位置上。

優(yōu)點:原理簡單;兼容性好,可以兼容到IE6、IE7;可以同時實現(xiàn)鏤空多個。

缺點:此方法只適合靜止頁面,不適合可以滾動的頁面。也不適合頁面內(nèi)容會發(fā)生變換的頁面。

代碼如下:

<div class="class1">
    <img src="images/000.jpg" alt=""/>
</div>

.class1{
    position: absolute;
    width:100%;
    height:100%;
    top: 0;
    left: 0;
    background-color: #000;
    opacity: 0.6;
    filter:alpha(opacity=60);
}
.class1 img{
    position: absolute;
    top:260px;
    left: 208px;
}

【 方法二:CSS3陰影屬性實現(xiàn) 】

原理:利用CSS3的陰影屬性。

優(yōu)點:實現(xiàn)方便;適合任何頁面,不會受頁面的限制。

缺點:兼容不太好,只能兼容到IE9。

代碼如下:

<div class="class2"></div>

.class2{
    position: absolute;
    width:170px;
    height:190px;
    top: 260px;
    left: 208px;
    box-shadow: rgba(0,0,0,.6) 0  0  0  100vh;
}

【方法三:CSS邊框?qū)傩詫崿F(xiàn) 】

原理:利用邊框?qū)傩?。先將一個空盒子定位在目標區(qū)域,然后在其四周用邊框填充。

優(yōu)點:實現(xiàn)方便,兼容性好,可以兼容到IE6、IE7;適合任何頁面,不會受頁面的限制。

缺點:要做兼容實現(xiàn)過程則相對復雜。

代碼如下:

<div class="class3"></div>
.class3{
      position: absolute;
      width:170px;
      height:190px;
      top: 0;
      left: 0;
      border-left-width:208px;
      border-left-style: solid;
      border-left-color:rgba(0,0,0,.6);
      border-right-width:970px;
      border-right-style: solid;
      border-right-color:rgba(0,0,0,.6);
      border-top-width:260px;
      border-top-style: solid;
      border-top-color:rgba(0,0,0,.6);
      border-bottom-width:253px;
      border-bottom-style: solid;
      border-bottom-color:rgba(0,0,0,.6);
}

【 方法四:SVG或者canvas 】

原理:利用SVG或者canvas的繪圖功能。

優(yōu)點:可以同時鏤空多個。

缺點:兼容性不好,實現(xiàn)過程相對復雜。

我以SVG為例,代碼如下:

<svg style="position: absolute;" width="1366" height="700">
    <defs>
        <mask id="myMask">
            <rect x="0" y="0" width="100%" height="100%" style="stroke:none; fill: #ccc"></rect>
            <rect id="circle1" width="170" height="190" x='208' y="260" style="fill: #000" />
        </mask>
    </defs>
    <rect x="0" y="0" width="100%" height="100%" style="stroke: none; fill: rgba(0, 0, 0, 0.6); mask: url(#myMask)"></rect>
</svg>

到此這篇關于css3遮罩層鏤空效果的多種實現(xiàn)方法的文章就介紹到這了,更多相關css3遮罩層鏤空內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持腳本之家!

相關文章

最新評論