When using a negative translate, how do you eliminate the extra space in the DOM from the original item position?
13:57 13 Oct 2026

I'm trying to implement a Solitaire game as a person project, and am using a negative translateY() value to have the cards stack on top of each other. (I had previously been using negative margins, but this was causing problems with the dndkit library for React that I'm using for drag-and-drop behavior.)

This visually accomplishes what it's supposed to, but as I understand it, this CSS function only changes the visual layout and not the underlying DOM structure. So those extra cards are still taking up vertical space as if they were in their original position, even though they aren't really since they've been shifted upwards. As a result, they're creating a bunch of empty space at the bottom that in my project is overflowing the parent container.

How do I fix this? I tried using overflow: clip and overflow: hidden, both of which do not work (the latter seemed to cause the lower cards to disappear altogether). I also saw some answers suggesting different values of position, but I'm not totally sure what to try there. The different values I've tried didn't seem to work. Here's a minimal JSFiddle reproduction:

https://jsfiddle.net/jpblair/csv9xdre/

Thanks!

css css-transforms