HTML5 Canvas & z-index issue in Google Chrome


When we apply z index to a canvas whose position is fixed, it stop causes chrome to render all other elements which have position:fixed properly. This only happens if canvas is greater than 256X256 px in size.

Wrap both h1 and canvas with the fixed div and solves the issue −

<div id = 'fixcontainer'>
   <h1>Test Title</h1>
   <canvas id = "backgroundCanvas" width = "1000" height = "300"></canvas>
</div>

The following is the CSS −

h1{
   position: fixed;
}
body{
   height: 1500px;
}
canvas{
   position: fixed; z-index: -10;
}

Updated on: 04-Mar-2020

508 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements