Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove mix-blend-mode from child element

How can I set mix-blend-mode on an element, but not it's children? Setting the children to the default value of normal does not seem to work:

http://jsfiddle.net/uoq916Ln/1/

like image 915
Choylton B. Higginbottom Avatar asked Jul 25 '15 18:07

Choylton B. Higginbottom


People also ask

What is the difference between Mix blend-mode difference and mix blend-mode exclusion?

difference : this subtracts the darker of the two colors from the lightest color. exclusion : similar to difference but with lower contrast. hue : creates a color with the hue of the content combined with the saturation and luminosity of the background.

What does mix blend-mode screen do?

The mix-blend-mode CSS property sets how an element's content should blend with the content of the element's parent and the element's background.

Why is mix blend-mode not working?

💡 If you find your CSS mix-blend-mode not working as expected (on a white background), you need to explicitly set a background-color on the underlying element. The easiest way to do so is to apply background-color: white; on the html and body elements.

What does exclusion blend-mode do?

Exclusion. Exclusion is very similar to Difference. Blending with white inverts the base color values, while blending with black produces no change. However, Blending with 50% gray produces 50% gray.


1 Answers

The solution on how to avoid mix-blend-mode affects children:

  1. Make child element position relative, give it a width and height;
  2. Create some real or pseudo element inside the child with absolute position, and apply mix-blend-mode to it;
  3. Create inner element inside the child for your content. Make it's position absolute, and put it on top of other elements;

Live example

html

<div class="bkdg">
    <div class="blend">
        <div class="inner">
            <h1>Header</h1>
        </div>
    </div>
</div>

css

.blend {
    position: relative; /* Make position relative */
    width: 100%;
    height: 100%;
}

.blend::before { /* Apply blend mode to this pseudo element */
    content: '';
    width: 100%;
    height: 100%;
    position: absolute;
    left: 0;
    top: 0;
    z-index: 1;
    background-color: green;
    mix-blend-mode: multiply;
}

.inner { /* This is our content, must have absolute position */
    position: absolute;
    z-index: 2;
}

h1 {
    color: white;
}
like image 64
Rashad Ibrahimov Avatar answered Sep 28 '22 22:09

Rashad Ibrahimov