這篇文章尚未翻譯 — 顯示英文版本。
Duotone in CSS, not in Photoshop
Exporting duotoned images from a design tool means shipping two copies of every photograph and swapping them on theme change. Doing it in CSS means the tint is a token, and the toggle is free.
The composite
Two stops: a dark colour behind the image, a light colour over it.
.duo {
position: relative;
background: var(--duo-shadow);
}
.duo img {
filter: grayscale(1) contrast(1.05);
mix-blend-mode: screen;
}
.duo::after {
content: "";
position: absolute;
inset: 0;
background: var(--duo-light);
mix-blend-mode: multiply;
}
The trap
Put filter: grayscale(1) on the container instead of the image and the whole
thing renders grey. The filter applies to the element's rendered result, which
by then includes the tint you just composited. Greyscale has to happen to the
photograph, before the blend, or it undoes the effect.
