您可能在某些網(wǎng)站上看到過以剪影形式播放的圖像或視頻。剪影可以是圖像、物體、人或動(dòng)物,以黑色表示,勾勒出主體的輪廓。我們可以在剪影中插入任何圖像或視頻,以便視頻或圖像將以剪影的顏色顯示
在本文中,我們將了解如何將圖像或視頻置于剪影中。
如何將對(duì)象放置在輪廓內(nèi)?
剪影是一個(gè)物體或人的圖像,由黑色或任何其他調(diào)色板顏色的實(shí)體形狀表示。現(xiàn)在,我們要在此處使用的屬性將是 mix-blend 屬性,所使用的屬性指定特定元素的內(nèi)容如何與其最近的父元素混合。
語法
以下是使用 mix-blend 屬性的語法 –
mix-blend mode: =darken,multiply,normal;
登錄后復(fù)制
混合混合模式具有正常、相乘、濾色和變暗等值,每個(gè)值都會(huì)更改與其最近的父級(jí)的混合關(guān)系。讓我們看一個(gè)示例以更好地理解此混合混合屬性。
示例
在下面的示例中,我們創(chuàng)建了三個(gè)容器,然后為它們提供了三個(gè)不同的類。然后在 CSS 部分,我們更改了寬度和高度以及邊框半徑,使其成為圓形,然后更改了所有圓形的顏色。預(yù)期輸出的代碼如下 –
<!DOCTYPE html> <html lang="en"> <head> <title>Example of using the mix-blend property</title> <style> .round { border-radius: 50%; width: 79px; mix-blend-mode: screen; height: 79px; position: absolute; } .round-one { background: red; } .round-second { left: 38px; background: yellow; } .round-third { left: 19px; background: blue; top: 39px; } .iso { position: relative; Isolation: isolate; } </style> </head> <body> <div class="isolate"> <div class="round round-one"></div> <div class="round round-two"></div> <div class="round round-third"></div> </div> </body> </html>
登錄后復(fù)制
如您所見,通過使用 mix-blend 屬性,我們將上面的圓圈與 2 種不同的顏色混合。
現(xiàn)在,我們知道了混合模式屬性的工作原理,我們將在剪影中放置圖像或視頻,并確保擁有執(zhí)行此操作所需的資源。讓我們查看代碼部分,看看如何在剪影中插入圖像或視頻。
示例
在此示例中,我們將使用混合混合模式屬性在剪影圖像中添加圖像。
在此,我們首先添加了剪影圖像,然后添加了我們要混合的圖像。接下來,我們將它們封裝在 div 下,然后給它們一個(gè)類。之后轉(zhuǎn)到 CSS 部分,然后在我們添加的圖像上使用 mix-blend mode 屬性并將值設(shè)置為 screen。讓我們看看使用以下代碼將獲得的輸出。
<!DOCTYPE html> <html lang="en"> <head> <title>Example of the silhoutte property</title> <style> .con { justify-content: center; display: flex; align-items: center; } body { min-height: 99vh; } .con .main { position: relative; width: 399px; margin: 48px; height: 399px; } * { padding: 0; margin: 0; box-sizing: border-box; } .con .main img { top: 0; left: 0; position: absolute; width: 98%; mix-blend-mode: screen; height: 99%; object-fit: cover; mix-blend-mode: screen; } </style> </head> <body> <div class="con"> <div class="main"> <img src="https://www.tutorialspoint.com/static/images/banner-img.png?v=2.001" /> <img src="https://www.tutorialspoint.com/images/logo.png" /> </div> </div> </body> </html>
登錄后復(fù)制
您可以在上面的輸出中看到,我們添加了剪影圖像,然后添加了另一張圖像,當(dāng)我們使用混合混合模式屬性時(shí),圖像與剪影混合在一起,看起來就像是同一張圖像而不是 2 個(gè)不同的圖像。
注意 – 我們可以對(duì)文本、圖像、SVG 使用混合混合模式屬性,支持混合混合模式屬性的瀏覽器有 chrome、edge、safari、Firefox 等。 p>
結(jié)論
剪影效果可用于使網(wǎng)站更具交互性和吸引力,并且只需使用 CSS 中的單個(gè)屬性即可完成,即 mix-blend 屬性,該屬性定義內(nèi)容如何與其最近的內(nèi)容混合父級(jí)和父級(jí)的背景。
在本文中,我們了解了如何使用一些 CSS 屬性(例如混合混合模式屬性)將圖像或視頻置于剪影中。
以上就是如何將圖像或視頻放置在剪影內(nèi)?的詳細(xì)內(nèi)容,更多請(qǐng)關(guān)注www.92cms.cn其它相關(guān)文章!