This article is welcome to be shared and aggregated. There is no need to reprint the full text. Please respect copyright. The circle is so small. If you need it urgently, you can contact us for authorization. 1. Maybe you all know First, let me tell you two points that you may know: 1. 2. After applying Next, let’s talk about some knowledge that you may not know. This is also the reason why many people are confused about why 2. What you may not know 1. Background order affects the blending effect The blending effect is closely related to the order of the background images in For example, the following two elements: <div class="ball"></div> <div class="ball2"></div> Set the background blending mode to overlay, but the order of the background images of the two elements is reversed. The code is as follows: .ball { width: 200px; height: 200px; border-radius: 50%; background: linear-gradient(deeppink, deeppink), linear-gradient(deepskyblue, deepskyblue); /* Apply overlay blend mode */ background-blend-mode: overlay; } .ball2 { width: 200px; height: 200px; border-radius: 50%; background: linear-gradient(deepskyblue, deepskyblue), linear-gradient(deeppink, deeppink); /* Apply overlay blend mode */ background-blend-mode: overlay; } The result is shown in the figure below. The 2. The mixing effect is the result of multiple mixing attributes acting simultaneously Many developers are not aware that .ball { background: linear-gradient(deeppink, deeppink), linear-gradient(deepskyblue, deepskyblue); background-blend-mode: overlay; } is actually equivalent to: .ball { background: linear-gradient(deeppink, deeppink), linear-gradient(deepskyblue, deepskyblue); background-blend-mode: overlay overlay; } That is, In other words, each background image actually has its own blending mode value, which is very different from We use an example to demonstrate how multiple values of <div class="box"></div> .box { width: 200px; height: 200px; background: linear-gradient(to right bottom, deeppink 50%, transparent 50%), linear-gradient(to top right, deeppink 50%, transparent 50%), darkblue; background-blend-mode: multiply, screen; position: relative; } /* The original deeppink color value in the middle*/ .box::before { content: ''; position: absolute; width: 33%; height: 33%; inset: 0; margin: auto; background-color: deeppink; } At this point, the in: The square area marked with serial number ① in the middle does not apply any blending mode, and the color is
Therefore, the final color value is the color value of the upper layer Because the color value of the underlying The above is the principle of the five colors of the 3. Background-blend-mode and implementation of gradient icons Finally, let’s take a look at why most people can’t use For example, now there is a small delete icon with a very dark color. In theory, we can use .icon-delete { background: linear-gradient(deepskyblue, deeppink), url(delete.png), white; background-blend-mode: lighten; } At first glance, it seems logically impeccable. The gradient and the black icon on a white background are mixed to brighten the color. No matter how you think, the black icon should also become a gradient color. Unfortunately, the final gradient is not a gradient color, but pure white. Why does this happen? That’s because .icon-delete { background: linear-gradient(deepskyblue, deeppink), url(delete.png), white; /* Actual calculated value */ background-blend-mode: lighten lighten; } That is, the delete icon Now that we know the problem, we also know how to solve it. It's very simple. Just make .icon-delete { background: linear-gradient(deepskyblue, deeppink), url(delete.png), white; /* Set the blending mode of the PNG icon to darken */ background-blend-mode: lighten darken; } Or: .icon-delete { background: linear-gradient(deepskyblue, deeppink), url(delete.png), white; /* Set the blending mode of the PNG icon to normal */ background-blend-mode: lighten normal; } It is recommended to use the Of course, the best way to achieve the gradient icon effect is definitely the CSS IV. Completion rules of background-blend-mode When the number of If the number of .example { background: linear-gradient(deepskyblue, deeppink), white; background-blend-mode: lighten, darken; } is equivalent to: .example { background: linear-gradient(deepskyblue, deeppink), white; background-blend-mode: lighten; } If the number of .example { background: linear-gradient(deepskyblue, deeppink), linear-gradient(deepskyblue, deeppink), linear-gradient(deepskyblue, deeppink), white; background-blend-mode: lighten, darken; } is equivalent to: .example { background: linear-gradient(deepskyblue, deeppink), linear-gradient(deepskyblue, deeppink), linear-gradient(deepskyblue, deeppink), white; background-blend-mode: lighten, darken, lighten; } That is, V. Conclusion The CSS The reason is: 1. Real-world photo images are rarely presented as background 2. The working mechanism of Therefore, I won’t go into details as this is not the main content of this article. This article address: https://www.zhangxinxu.com/wordpress/?p=9499 This concludes this article on in-depth understanding of the working mechanism of CSS background-blend-mode. For more information on the working mechanism of CSS background-blend-mode, please search previous articles on 123WORDPRESS.COM or continue to browse the related articles below. I hope you will support 123WORDPRESS.COM in the future! |
<<: CSS element hiding principle and display:none and visibility:hidden
>>: Implementation of mysql configuration SSL certificate login
1. Optimize Nginx concurrency [root@proxy ~]# ab ...
Preface When writing front-end pages, we often us...
Table of contents 1. Docker installation on Mac 2...
getElementById cannot get the object There is a s...
background The company code is provided to third ...
Preface Node will be used as the middle layer in ...
Glass Windows What we are going to achieve today ...
1. Basic syntax structure of HTML submit and bott...
A. Installation of MySQL backup tool xtrabackup 1...
Import: Due to project requirements, we will enca...
A distinct Meaning: distinct is used to query the...
Web design, according to personal preferences and ...
This article shares the specific code of jQuery t...
Input subsystem framework The linux input subsyst...
Table of contents Overview Problem Description Ci...