EN
CSS - invert color
0 points
In this article, we would like to show you how to invert element colors using CSS.
Quick solution:
xxxxxxxxxx
1
.inverted {
2
filter: invert(1); /* <----- 100% inversion */
3
}
4
5
.half-inverted {
6
filter: invert(50%); /* <----- 50% inversion */
7
}
In this example, we present how to use the invert()
filter with percentage and fractional values.
xxxxxxxxxx
1
2
<html>
3
<head>
4
<style>
5
6
img {
7
height: 100px;
8
margin: 5px;
9
}
10
11
.partly-inverted {
12
filter: invert(0.25); /* <----- 25% inversion */
13
}
14
15
.inverted {
16
filter: invert(100%); /* <----- 100% inversion */
17
}
18
19
</style>
20
</head>
21
<body style="display: flex">
22
<img src="https://dirask.com/static/bucket/1574890428058-BZOQxN2D3p--image.png" />
23
<img class="partly-inverted" src="https://dirask.com/static/bucket/1574890428058-BZOQxN2D3p--image.png" />
24
<img class="inverted" src="https://dirask.com/static/bucket/1574890428058-BZOQxN2D3p--image.png" />
25
</body>
26
</html>