在之前的文章《利用CSS3創(chuàng)建實(shí)用的加載動(dòng)畫效果(兩種)》中,我們分享了兩種使用CSS3實(shí)現(xiàn)的加載動(dòng)畫效果。這次我們給大家介紹一下利用CSS如何將兩個(gè)圖片疊加融合在一起,創(chuàng)建唯美效果,感興趣的可以學(xué)習(xí)了解一下~
今天本文給大家分享兩種利用CSS3將兩個(gè)圖片疊加融合在一起顯示的特效。廢話不多說,我們直接開始吧~
第一種方法:利用mix-blend-mode屬性
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <style> body { background-color: black; } .center { text-align: center; display: block; } .cool_effect img:first-child { position: absolute; mix-blend-mode: soft-light; } </style> </head> <body> <div class="center"> <div class="cool_effect"> <img src="https://img.php.cn/upload/article/000/000/024/61289cbf3781b804.jpg"> <img src="https://img.php.cn/upload/article/000/000/024/61289ccb2cf43141.jpg"> </div> </div> </body> </html>
利用:first-child
選擇器選中第一個(gè)img圖片,給他設(shè)置絕對(duì)定位;然后利用添加關(guān)鍵代碼mix-blend-mode: soft-light;
設(shè)置融合混合模式,將上下兩張圖片融合在一起。
效果圖如下:
說明:mix-blend-mode 屬性描述了元素的內(nèi)容應(yīng)該與元素的直系父元素的內(nèi)容和元素的背景如何混合。
取值情況: mix-blend-mode: normal; // 正常 mix-blend-mode: multiply; // 正片疊底 mix-blend-mode: screen; // 濾色 mix-blend-mode: overlay; // 疊加 mix-blend-mode: darken; // 變暗 mix-blend-mode: lighten; // 變亮 mix-blend-mode: color-dodge; // 顏色減淡 mix-blend-mode: color-burn; // 顏色加深 mix-blend-mode: hard-light; // 強(qiáng)光 mix-blend-mode: soft-light; // 柔光 mix-blend-mode: difference; // 差值 mix-blend-mode: exclusion; // 排除 mix-blend-mode: hue; // 色相 mix-blend-mode: saturation; // 飽和度 mix-blend-mode: color; // 顏色 mix-blend-mode: luminosity; // 亮度 按效果來分可以分為這幾類: 基礎(chǔ)混合模式 normal 利用圖層透明度和不透明度來控制與下面的圖層混合 降暗混合模式 darken,multiply,color-burn 減色模式,濾掉圖像中高亮色,從而達(dá)到圖像變暗 加亮混合模式 screen,lighten,color-dodge 加色模式,濾掉圖像中暗色,從而達(dá)到圖像變亮 融合混合模式 overlay,soft-light,hard-light 用于不同程度的對(duì)上、下兩圖層的融合 變異混合模式 difference,exclusion,hard-light 用于制作各種變異的圖層混合 色彩疊加混合模式 hue,saturation,color,luminosity 根據(jù)圖層的色相,飽和度等基本屬性,完成圖層融合
方法2:利用背景屬性
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <style> body { background-image: url(https://img.php.cn/upload/article/000/000/024/6128a4d8808ab560.png), url(https://img.php.cn/upload/article/000/000/024/6128c89393fce968.jpg); background-position: top, top; background-repeat: repeat, no-repeat; background-size: contain, cover; } </style> </head> <body> </div> </body> </html>
直接在background-image中指定多個(gè)背景路徑即可,效果圖如下:
PHP中文網(wǎng)平臺(tái)有非常多的視頻教學(xué)資源,歡迎大家學(xué)習(xí)《css視頻教程》!