react-three-fiber
react-three-fiber copied to clipboard
Canvas expands when inside a CSS grid
My page has a basic CSS grid layout. It's responsive, so each panel changes as the size of the parent changes. See video below:
https://user-images.githubusercontent.com/35771636/185619171-09534f08-a88a-4849-8cc3-cbc93333e748.mov
When I replace the C panel with a basic <Canvas>
element, the panel starts off with a certain width but immediately expands to some unknown value. In addition, the responsiveness is broken.
https://user-images.githubusercontent.com/35771636/185619750-94728dbb-e189-437d-a6a0-506260e975fc.mov
I cannot for the life of me figure out why this is happening. I have tried modifying the size of the parent div. I have tried setting a manual width to the canvas which also appears to break things further.
How do I make the canvas respect the initial size of its panel? How do I make the canvas responsive?
Is this a bug or something wrong with my CSS?
👉 Code Sandbox
I have the same probleme... Can someone explain ?
docs - https://webglfundamentals.org/webgl/lessons/webgl-resizing-the-canvas.html
This is often the case when dealing with canvas. You may have to solve it with JavaScript instead of css.
If it's a cnavas without a background in the model, Fix the canvas to the center in the grid-column and use it.
This is my old project screen.
I hope it helps you.
good thankyou
I ended up finding an alternative solution. css grid are by default not allowed to shrink below the content size.. By setting min-height and min-width to 0 on the parent div of the canvas. The canvas will shrink correctly.