react-three-fiber icon indicating copy to clipboard operation
react-three-fiber copied to clipboard

Canvas expands when inside a CSS grid

Open petargyurov opened this issue 2 years ago • 2 comments

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

petargyurov avatar Aug 19 '22 12:08 petargyurov

I have the same probleme... Can someone explain ?

Yasha-ops avatar Aug 26 '22 21:08 Yasha-ops

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.

ezgif com-gif-maker

I hope it helps you.

chuhongkyu avatar Aug 29 '22 00:08 chuhongkyu

good thankyou

dahuigeniu avatar Jan 24 '23 15:01 dahuigeniu

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.

rockandsalt avatar Mar 13 '23 17:03 rockandsalt