Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mix-blend-mode broken when html has "perspective"

By applying "perspective" to the html element my mix-blend-mode seems to get ignored by Firefox.

html {
    perspective: 800px; /* causing the issue */
}

div {
    color: #fff;    
    background: linear-gradient(to bottom, #000, orange);
    mix-blend-mode: screen;
}

What is the issue with that? I am using Firefox 40.

http://codepen.io/Type-Style/pen/oXJbRE

like image 769
Type-Style Avatar asked Jul 31 '15 14:07

Type-Style


People also ask

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 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.

How does Mix-blend-mode work?

mix-blend-mode is a CSS property that defines how the content of an element should blend with the content of the element's parent and its background. With this, you can create nice blends and colors for parts of an element's content depending on its direct background.

Which CSS property is used to set the blend mode?

The background-blend-mode Property defines how the element's background image should blend with each other and with the element's background-color.


2 Answers

It looks like you can achieve your expected result by simply adding a mix-blend-mode to the html element.

Working Example

html {
  background-color: #111;
  background-image: url(https://upload.wikimedia.org/wikipedia/commons/thumb/e/ed/W3C%C2%AE_Icon.svg/210px-W3C%C2%AE_Icon.svg.png);
  background-repeat: no-repeat;
  perspective: 800px;
  mix-blend-mode: screen; /*see change here*/
}
div {
  height: 100px;
  line-height: 100px;
  font-size: 40px;
  color: #fff;
  background: linear-gradient(to bottom, #000, orange);
  mix-blend-mode: screen;
}
<div>Some Text</div>
<div>Some more Text</div>

I'm not entirely sure what was causing the issue, but both perspective and mix-blend-mode will create a new stacking context so it may have something to do with that...

like image 142
apaul Avatar answered Oct 03 '22 09:10

apaul


Despite the fact that, when defining the perspective property for an element, it is the CHILD elements that get the perspective view, NOT the element itself, you still have to call on your child element, and assign your desired CSS perspective properties to it, in order to have it running cross-browser. The codes below are working 100% an any existing browser;

html {
    background-color: #111;
    background-image: url(https://upload.wikimedia.org/wikipedia/commons/thumb/e/ed/W3C%C2%AE_Icon.svg/210px-W3C%C2%AE_Icon.svg.png);
    background-repeat: no-repeat;  
} 

div {
    height: 100px; line-height: 100px;
    font-size: 40px;
    color: #fff;    
    background: linear-gradient(to bottom, #000, orange);
    mix-blend-mode: screen;
}

.background-image{
    perspective: 50px; // calling on child element and applying the perspective
}

What was the issue?

Defining your perspective properties under the HTML tag causes issues for cross-browsers compatibility, as you may have numerous elements under your main html tag, and the browser may not distinguish how and which element to apply it to. It is true that the perspective property only affects 3D transformed elements, but it's not a guaranty that any browsers detects and applies it to the image specified as a main background. I hope it helped.

like image 23
Pouya Ataei Avatar answered Oct 03 '22 08:10

Pouya Ataei