今天本文給大家分享兩種利用CSS3將兩個圖片疊加融合在一起顯示的特效。廢話不多說,我們直接開始吧~
第一種方法:利用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>
<body>
<div class="center">
<div class="cool_effect">
<img src="001.jpg">
<img src="002.jpg">
</div>
</div>
</body>
</html>
利用:first-child選擇器選中第一個img圖片,給他設置絕對定位;然后利用添加關鍵代碼mix-blend-mode: soft-light;設置融合混合模式,將上下兩張圖片融合在一起。
效果圖如下:

說明:mix-blend-mode 屬性描述了元素的內容應該與元素的直系父元素的內容和元素的背景如何混合。
取值情況: 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; // 強光 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; // 亮度 按效果來分可以分為這幾類: 基礎混合模式 normal 利用圖層透明度和不透明度來控制與下面的圖層混合 降暗混合模式 darken,multiply,color-burn 減色模式,濾掉圖像中高亮色,從而達到圖像變暗 加亮混合模式 screen,lighten,color-dodge 加色模式,濾掉圖像中暗色,從而達到圖像變亮 融合混合模式 overlay,soft-light,hard-light 用於不同程度的對上、下兩圖層的融合 變異混合模式 difference,exclusion,hard-light 用於制作各種變異的圖層混合 色彩疊加混合模式 hue,saturation,color,luminosity 根據圖層的色相,飽和度等基本屬性,完成圖層融合
方法2:利用背景屬性
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<style>
body {
background-image: url(001.png),
url(003.jpg);
background-position: top, top;
background-repeat: repeat, no-repeat;
background-size: contain, cover;
}
</style>
</head>
<body>
</body>
</html>
直接在background-image中指定多個背景路徑即可,效果圖如下:

以上就是超實用!利用CSS3將兩個圖片疊加在一起顯示的詳細內容。(拼多多培訓)
