Reputation: 9
I'm working on a project using React where I render individual pixels as elements (or in some cases). However, on mobile devices, some pixels appear distorted—they stretch into rectangles rather than staying as perfect squares.
Here’s a simplified snippet of how I render each pixel:
<div
style={{
position: "absolute",
top: pixelPosition.y * PIXEL_SIZE,
left: pixelPosition.x * PIXEL_SIZE,
width: `${PIXEL_SIZE}px`,
height: `${PIXEL_SIZE}px`,
backgroundColor: `${selectedColor}`,
boxSizing: "border-box",
pointerEvents: "none",
imageRendering: "pixelated"
}}
/>
Even though PIXEL_SIZE is set to 1px, some pixels appear stretched on certain mobile screens.
I’ve attached an image showing the issue.
This is meta data from index.html
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
Why does this happen specifically on mobile? Are there any CSS properties or rendering techniques that can ensure perfect 1:1 pixel mapping? Any insights would be greatly appreciated!
Upvotes: 0
Views: 39