I'm learning React with Vite and built a small app with login and registration forms. The cards are supposed to be centered, but the whole layout looks slightly slanted or shifted to the right on my phone. The gap from the left edge of the screen to the form seems larger than the gap on the right. What could be causing this, and how can I fix it?
3 Answers
You can check for horizontal overflow without using developer tools by temporarily logging the document widths in a React effect: `useEffect(() => { const root = document.documentElement; alert(root.scrollWidth + ' vs ' + root.clientWidth); }, []);`. If `scrollWidth` is larger than `clientWidth`, something is extending beyond the screen. You can then inspect elements and look for one whose right edge is beyond the viewport. I’d examine the divider and other full-width elements first rather than hiding the problem with `overflow-x: hidden`.
The login and registration cards appear centered by themselves, so the issue may be coming from another element affecting the page width. A divider or full-width element using `100vw`, a negative margin, or an oversized fixed width is a likely culprit. `100vw` can also include the scrollbar width on desktop, which can make centered content look slightly offset.
If the entire page is drifting right, check the padding and margins on the parent containers first. An element may be wider than the viewport, causing the form to center within the page’s scrollable width instead of the visible screen. On a larger device, you can use the browser’s developer tools to compare the left and right edges of the outer container.

Thanks so much for the explanation. I’ll check the divider and compare the document widths from my phone.