Overlay layer
It happens that you might want to have a layer that comes over the element content, it can be done with CSS ::before pseudo-element, however, it is a common use case, creating this layer each time is not a logical choice.
FlatifyCSS gives you a helper class called .overlay-layer, it does the same thing and you can just customize it easily without writing boilerplates.
Overlay layers have a couple of CSS variables to make them more flexible:
| Variable | Default | Notes |
|---|---|---|
--flatify__overlay-layer-priority | 10 | The z-index of the layer |
--flatify__overlay-layer-bg-color | var(--flatify__bg-color) | Same as the page background |
--flatify__overlay-layer-opacity | 1 | 1 means 100% |
--flatify__overlay-layer-blending-mode | normal | Any mix-blend-mode value |
--flatify__overlay-layer-backdrop-filter | none | Any backdrop-filter value |
In the example below there is a box with an image inside it, and an overlay layer changes the image color with mix-blend-mode CSS property and add some effect with backdrop-filter CSS property.
index.html
<div class="my-img-fx">
<img src="https://picsum.photos/500/300" alt="a random image" />
</div>
<div class="my-img-fx fx-1 overlay-layer">
<img src="https://picsum.photos/500/300" alt="a random image" />
</div>
<div class="my-img-fx fx-2 overlay-layer">
<img src="https://picsum.photos/500/300" alt="a random image" />
</div>
<div class="my-img-fx fx-3 overlay-layer">
<img src="https://picsum.photos/500/300" alt="a random image" />
</div>
<div class="my-img-fx fx-4 overlay-layer">
<img src="https://picsum.photos/500/300" alt="a random image" />
</div>
<div class="my-img-fx fx-5 overlay-layer">
<img src="https://picsum.photos/500/300" alt="a random image" />
</div>
<div class="my-img-fx fx-6 overlay-layer">
<img src="https://picsum.photos/500/300" alt="a random image" />
</div>
<div class="my-img-fx fx-7 overlay-layer">
<img src="https://picsum.photos/500/300" alt="a random image" />
</div>
style.scss
.my-img-fx {
overflow: hidden;
width: 300px;
height: 150px;
margin: 0.5em;
border-radius: 1em;
}
.my-img-fx img {
width: 100%;
height: 100%;
object-fit: cover;
}
.fx-1 {
--flatify__overlay-layer-bg-color: linear-gradient(to right, #2c5364, #203a43, #0f2027);
--flatify__overlay-layer-blending-mode: overlay;
}
.fx-2 {
--flatify__overlay-layer-bg-color: linear-gradient(to right, #8e2de2, #4a00e0);
--flatify__overlay-layer-blending-mode: hard-light;
}
.fx-3 {
--flatify__overlay-layer-bg-color: linear-gradient(to right, #f12711, #f5af19);
--flatify__overlay-layer-blending-mode: multiply;
--flatify__overlay-layer-opacity: 0.75;
}
.fx-4 {
--flatify__overlay-layer-bg-color: rgba(255, 255, 255, 0.5);
--flatify__overlay-layer-backdrop-filter: blur(3px) contrast(120%);
}
.fx-5 {
--flatify__overlay-layer-bg-color: trasparent;
--flatify__overlay-layer-backdrop-filter: contrast(400%) saturate(400%) grayscale(50%) sepia(50%) hue-rotate(10deg);
}
.fx-6 {
--flatify__overlay-layer-bg-color: trasparent;
--flatify__overlay-layer-backdrop-filter: sepia(75%) hue-rotate(-25deg);
}
.fx-7 {
--flatify__overlay-layer-bg-color: trasparent;
--flatify__overlay-layer-backdrop-filter: grayscale(100%) contrast(140%) brightness(85%);
}