Свойство CSS mix-blend-mode
Свойство mix-blend-mode определяет смешивание содержимого элемента с фоном его непосредственного родителя. Для смешивания нужно иметь background-image, background-color или <img>.
В CSS доступно 16 режимов смешивания. Если для элемента задано значение, отличное от “normal” (значение по умолчанию), для этого элемента будет создан новый контекст наложения. Затем вновь сформированная группа должна смешиваться с контекстом наложения, который содержит элемент. Элемент не будет смешиваться с содержимым, находящимся вне контекста наложения.
Любое свойство, которое приводит к созданию контекста наложения, может влиять на смешивание.
Для изоляции элемента можно использовать свойство isolation.
TIP
Если вы хотите смешать фоновые изображения элемента между собой, можно использовать свойство background-blend-mode.
| Initial Value | normal |
|---|---|
| Applies to | All elements. |
| Inherited | No. |
| Animatable | No. |
| Version | CSS1 |
| DOM Syntax | object.style.mixBlendMode = "exclusion"; |
Синтаксис
Синтаксис свойства CSS mix-blend-mode
mix-blend-mode: normal | multiply | screen | overlay | darken | lighten | color-dodge | color-burn | difference | exclusion | hue | saturation | color | luminosity | initial | inherit;Пример свойства mix-blend-mode:
Пример свойства CSS mix-blend-mode со значением multiply
<!DOCTYPE html>
<html>
<head>
<title>The title of the document</title>
<style>
.example {
background-color: #8ebf42;
height: 800px;
}
img {
width: 100%;
height: auto;
float: left;
mix-blend-mode: multiply;
}
</style>
</head>
<body>
<h2>Mix-blend-mode property example</h2>
<h3>Mix-blend-mode: multiply</h3>
<div class="example">
<img src="https://ru.w3docs.com/uploads/media/default/0001/01/b408569013c0bb32b2afb0f0d45e93e982347951.jpeg" alt="Tree" />
</div>
</body>
</html>Пример свойства mix-blend-mode со значением "screen":
Пример свойства CSS mix-blend-mode со значением screen
<!DOCTYPE html>
<html>
<head>
<title>The title of the document</title>
<style>
.example {
background-color: #8ebf42;
height: 800px;
}
img {
width: 100%;
height: auto;
float: left;
mix-blend-mode: screen;
}
</style>
</head>
<body>
<h2>Mix-blend-mode property example</h2>
<h3>Mix-blend-mode: screen</h3>
<div class="example">
<img src="https://ru.w3docs.com/uploads/media/default/0001/01/b408569013c0bb32b2afb0f0d45e93e982347951.jpeg" alt="Tree" />
</div>
</body>
</html>Пример свойства mix-blend-mode со значением "color-dodge":
Пример свойства CSS mix-blend-mode со значением color-dodge
<!DOCTYPE html>
<html>
<head>
<title>The title of the document</title>
<style>
.example {
background-color: #8ebf42;
height: 800px;
}
img {
width: 100%;
height: auto;
float: left;
mix-blend-mode: color-dodge;
}
</style>
</head>
<body>
<h2>Mix-blend-mode property example</h2>
<h3>Mix-blend-mode: color-dodge</h3>
<div class="example">
<img src="https://ru.w3docs.com/uploads/media/default/0001/01/b408569013c0bb32b2afb0f0d45e93e982347951.jpeg" alt="Tree" />
</div>
</body>
</html>Пример свойства mix-blend-mode со значением "hue":
Пример свойства CSS mix-blend-mode со значением hue
<!DOCTYPE html>
<html>
<head>
<title>The title of the document</title>
<style>
.example {
background-color: #8ebf42;
height: 800px;
}
img {
width: 100%;
height: auto;
float: left;
mix-blend-mode: hue;
}
</style>
</head>
<body>
<h2>Mix-blend-mode property example</h2>
<h3>Mix-blend-mode: hue</h3>
<div class="example">
<img src="https://ru.w3docs.com/uploads/media/default/0001/01/b408569013c0bb32b2afb0f0d45e93e982347951.jpeg" alt="Tree" />
</div>
</body>
</html>Пример свойства mix-blend-mode со значением "normal":
Свойство CSS mix-blend-mode
<!DOCTYPE html>
<html>
<head>
<title>Title of the document</title>
<style>
.example {
background-color: #ff0000;
height: 500px;
}
img {
width: 50%;
height: auto;
float: left;
mix-blend-mode: normal;
}
</style>
</head>
<body>
<h2>Mix-blend-mode property example</h2>
<h3>Mix-blend-mode: normal</h3>
<div class="example">
<img src="https://ru.w3docs.com/uploads/media/default/0001/01/b408569013c0bb32b2afb0f0d45e93e982347951.jpeg" alt="Tree" width="300" height="300" />
</div>
</body>
</html>Пример свойства mix-blend-mode со значением "hard-light":
Свойство CSS mix-blend-mode
<!DOCTYPE html>
<html>
<head>
<title>Title of the document</title>
<style>
.example {
background-color: #ff0000;
height: 400px;
}
img {
width: 50%;
height: auto;
float: left;
mix-blend-mode: hard-light;
}
</style>
</head>
<body>
<h2>Mix-blend-mode property example</h2>
<h3>Mix-blend-mode: hard-light</h3>
<div class="example">
<img src="https://ru.w3docs.com/uploads/media/default/0001/01/b408569013c0bb32b2afb0f0d45e93e982347951.jpeg" alt="Tree" width="300" height="300" />
</div>
</body>
</html>Пример свойства mix-blend-mode со значением "difference":
Свойство CSS mix-blend-mode
<!DOCTYPE html>
<html>
<head>
<title>Title of the document</title>
<style>
.example {
background-color: #ff0000;
height: 400px;
}
img {
width: 50%;
height: auto;
float: left;
mix-blend-mode: difference;
}
</style>
</head>
<body>
<h2>Mix-blend-mode property example</h2>
<h3>Mix-blend-mode: difference</h3>
<div class="example">
<img src="https://ru.w3docs.com/uploads/media/default/0001/01/b408569013c0bb32b2afb0f0d45e93e982347951.jpeg" alt="Tree" width="300" height="300" />
</div>
</body>
</html>Значения
| Value | Description |
|---|---|
| normal | Устанавливает режим смешивания в normal. Это значение свойства по умолчанию. |
| multiply | Устанавливает режим смешивания в multiply. |
| screen | Устанавливает режим смешивания в screen. |
| overlay | Устанавливает режим смешивания в overlay. |
| darken | Устанавливает режим смешивания в darken. |
| lighten | Устанавливает режим смешивания в lighten. |
| color-dodge | Устанавливает режим смешивания в color-dodge. |
| color-burn | Устанавливает режим смешивания в color-burn. |
| exclusion | Устанавливает режим смешивания в exclusion. |
| difference | Устанавливает режим смешивания в difference. |
| hue | Устанавливает режим смешивания в hue. |
| saturation | Устанавливает режим смешивания в saturation. |
| color | Устанавливает режим смешивания в color. |
| luminosity | Устанавливает режим смешивания в luminosity. |
| initial | Делает так, чтобы свойство использовало значение по умолчанию. |
| inherit | Наследует свойство от родительского элемента. |
Practice
Which of the following browser versions do not support the CSS mix-blend-mode property?