Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Position Fixed not working when CSS Filters applied on same element in Microsoft Edge

I am testing this on Edge 20.10240.16384.0

I have an element whose position is fixed and has CSS Filters applied to it. This works great in all browsers except Microsoft Edge, where the position of the element doesn't remain fixed. This issue is directly related to CSS3 Filters as removing them makes the position fixed work correctly

Here is a basic example of this. It works correctly (aka the fixed background remains fixed) on browsers other than Microsoft Edge.

<!DOCTYPE html>
<html>

<head>
  <style>
    body {
      height: 5000px;
    }
    
    .fixed {
      position: fixed;
      left: 0;
      background-image: url(https://lh5.googleusercontent.com/-REJ8pezTyCQ/SDlvLzhAH-I/AAAAAAAABeQ/mC1PXNiheJU/s800/Blog_background_750.gif);
      background-repeat: repeat;
      background-attachment: fixed;
      height: 100%;
      width: 100%;
      -webkit-filter: brightness(70%);
      -moz-filter: brightness(70%);
      -o-filter: brightness(70%);
      filter: brightness(70%);
    }
  </style>
</head>

<body>
  <div class='fixed'></div>
</body>

</html>

After searching around , I came across https://connect.microsoft.com/IE/feedback/details/1810480/ms-edge-rendering-problem-of-css-filter , which details the same issue but has been marked as Fixed most likely as it couldn't be reproduced. I am attaching GIF for the same -

Microsoft Edge - enter image description here

Google Chrome - enter image description here

like image 997
Prayag Verma Avatar asked Mar 03 '16 18:03

Prayag Verma


People also ask

How do you fix fixed positions?

Set everything up as you would if you want to position: absolute inside a position: relative container, and then create a new fixed position div inside the div with position: absolute , but do not set its top and left properties. It will then be fixed wherever you want it, relative to the container.

What is the difference between position fixed and sticky?

An element with position: sticky; is positioned based on the user's scroll position. A sticky element toggles between relative and fixed , depending on the scroll position. It is positioned relative until a given offset position is met in the viewport - then it "sticks" in place (like position:fixed).

How absolute positioning works?

Absolute positioningElements that are relatively positioned remain in the normal flow of the document. In contrast, an element that is absolutely positioned is taken out of the flow; thus, other elements are positioned as if it did not exist.

What is position fixed?

A fixed position element is positioned relative to the viewport, or the browser window itself. The viewport doesn't change when the window is scrolled, so a fixed positioned element will stay right where it is when the page is scrolled.


1 Answers

It is a bug, ms-edge-rendering-problem-of-css-filter, should have been fixed but obviously not.

Here is a workaround, where you still can use position: fixed and the image and filter is set using the :after pseudo-element.

body {
  height: 5000px;
}

.fixed {
  position: fixed;
  left: 0;
  height: 100%;
  width: 100%;
}
.fixed:after {
  content: ' ';
  position: absolute;
  left:0;
  top: 0;
  height: 100%;
  width: 100%;
  background-image: url(https://lh5.googleusercontent.com/-REJ8pezTyCQ/SDlvLzhAH-I/AAAAAAAABeQ/mC1PXNiheJU/s800/Blog_background_750.gif);
  background-repeat: repeat;
  background-attachment: fixed;
  -webkit-filter: brightness(70%);
  -moz-filter: brightness(70%);
  -o-filter: brightness(70%);
  filter: brightness(70%);
}
<div class='fixed'></div>
like image 124
Asons Avatar answered Sep 19 '22 15:09

Asons