Fixed element disappears in Chrome

CssWebkitPosition

Css Problem Overview


When scrolling on a website I've built, using the CSS property position: fixed works as expected to keep a navigation bar at the very top of the page.

In Chrome, however, if you use the links in the navigation bar it sometimes disappears. Usually, the item you've clicked on is still visible, but not always. Sometimes the entire thing disappears. Moving the mouse around brings back part of the element, and scrolling with the scroll wheel or arrow keys just one click brings the element back. You can see it happening (intermittently) on https://nikeplusphp.charanj.it - you might have to click on a few of the navigation the links a few times to see it happen.

I've also tried playing with the z-index and the visibility/display type but with no luck.

I came across this question but the fix didn't work for me at all. Seems to be a webkit issue as IE and Firefox work just fine.

Is this a known issue or is there a fix to keep fixed elements visible?

Update:

Only effects elements that have top: 0;, I tried bottom: 0; and that works as expected.

Css Solutions


Solution 1 - Css

Add -webkit-transform: translateZ(0) to the position: fixed element. This forces Chrome to use hardware acceleration to continuously paint the fixed element and avoid this bizarre behavior.

I created a Chrome bug for this https://bugs.chromium.org/p/chromium/issues/detail?id=288747. Please star it so this can get some attention.

Solution 2 - Css

This fixes it for me:

html, body {height:100%;overflow:auto}

Solution 3 - Css

I was having the same issue with Chrome, it seems to be a bug that occurs when there is too much going on inside the page, I was able to fix it by adding the following transform code to the fixed position element, (transform: translateZ(0);-webkit-transform: translateZ(0);) that forces the browser to use hardware acceleration to access the device’s graphical processing unit (GPU) to make pixels fly. Web applications, on the other hand, run in the context of the browser, which lets the software do most (if not all) of the rendering, resulting in less horsepower for transitions. But the Web has been catching up, and most browser vendors now provide graphical hardware acceleration by means of particular CSS rules.

Using -webkit-transform: translate3d(0,0,0); will kick the GPU into action for the CSS transitions, making them smoother (higher FPS).

Note: translate3d(0,0,0) does nothing in terms of what you see. it moves the object by 0px in x,y and z axis. It's only a technique to force the hardware acceleration.

#element {
	position: fixed;
	background: white;
	border-bottom: 2px solid #eaeaea;
	width: 100%;
	left: 0;
	top: 0;
	z-index: 9994;
	height: 80px;
    /* MAGIC HAPPENS HERE */
	transform: translateZ(0);
	-webkit-transform: translateZ(0);
}

Solution 4 - Css

The options above were not working for me until I mixed two of the solutions provided.

By adding the following to the fixed element, it worked. Basically z-index was also needed for me:

-webkit-transform: translateZ(0);
z-index: 1000;

Solution 5 - Css

This is a webkit issue that has yet to be resolved, oddly making the jump with JavaScript, rather than using the # url value, doesn't cause the problem. To overcome the issue, I supplied a JavaScript version that takes the anchor value and finds the absolute position of the element with that ID and jump to that:

var elements = document.getElementsByTagName('a');
for(var i = 1; i < elements.length; i++) {
    elements[i].onclick = function() {
        var hash = this.hash.substr(1),
            elementTop = document.getElementById(hash).offsetTop;
        window.scrollTo(0, elementTop + 125);
        window.location.hash = '';
        return false;
    }
}

I could refine this further and make it is that only it only looks for links beginning with a #, rather than ever a tag it finds.

Solution 6 - Css

If it don't work after adding

>-webkit-transform: translateZ(0)

than also add > user-scalable=no

on viewport meta

source here

it worked for me

Solution 7 - Css

I encountered the same issue in a different case. It was because of usage of same id in multiple place. For example i used #full 2 divs.

It seems that mozilla and I.E. supports usage of same id in multiple cases. But chrome doesnot. It reacted with fixed element disappering in my case.

Just removing the id's solved the problem.

Solution 8 - Css

None of them worked for me except calling the modal via javascript

<a href="#\" onclick="show_modal();">Click me to open MyModal</a>
<script>
function show_modal()
{
  MyModal.style.display = 'block';
}
</script>

other than this, none of the solutions above solved my problem.

Solution 9 - Css

This Worked for me . Add Overflow property to your top most container which can be Div or Form etc.

div, form
{
  overflow:visible;    
}

Solution 10 - Css

The same issue happened to me. For the main page of the website. I made a fixed header and Used an image for the front poster. Everything worked fine. But the moment I changed the opacity of the poster image my header with position: fixed; got disappeared. It was present there in the chrome developer tools. But was totally transparent on the website.

I tried every solution from StackOverflow, W3shools, Geeke4geeks. But if one thing was fixed another thing got messed up.

So I just opened photoshop and edited the image manually. And then posted it on my website. It worked. But still, it won't be effective for divs under the fixed elements.

Solution 11 - Css

If none of the answers above worked for you, make sure you aren't a dummy like me and have overflow: hidden; set on the fixed element :(

Solution 12 - Css

What if none of above worked at all? simple case of sticky header + mobile side menu pushing content.

I try to find a way to avoid fixed element (sticky header) being translated but in this case nothing is a good alternative.

So as there is no workaround on scope so far there is a JS alternative that I opted for to recalculate absolute position of fixed element. See here: https://stackoverflow.com/a/21487975/2012407

Solution 13 - Css

In my case, I just added min-height: 100vh; to fixed element, may be that will be useful for somebody

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestioncchanaView Question on Stackoverflow
Solution 1 - CssTJ VanTollView Answer on Stackoverflow
Solution 2 - CssCooperView Answer on Stackoverflow
Solution 3 - CssNeoView Answer on Stackoverflow
Solution 4 - CsscortopyView Answer on Stackoverflow
Solution 5 - CsscchanaView Answer on Stackoverflow
Solution 6 - CssGentiElezajView Answer on Stackoverflow
Solution 7 - CssRitesh Jung ThapaView Answer on Stackoverflow
Solution 8 - CssmaslanView Answer on Stackoverflow
Solution 9 - Csskumar chandraketuView Answer on Stackoverflow
Solution 10 - Cssamit.exeView Answer on Stackoverflow
Solution 11 - CssAngelika JohanssonView Answer on Stackoverflow
Solution 12 - CssantoniView Answer on Stackoverflow
Solution 13 - CssKirill HrudzinskiView Answer on Stackoverflow