There is a UI library called AceternityUI who does this but not with pure css. You can check their MacBook Scroll component. They are free and OpenSource. Rotating an object in 3 dimensions but showing them in 2d is not an easy case, I don't think it is possible with css.
But you can expand the bottom and narrow the top of the image which will make it look like it is rotated in X axis using JavaScript (or TypeScript).