I'm searching a way to prevent your whole body layout to resize when a scroll bar appears to the right. I want my body to stay at the exact same position when you switch from one html file to another, but the second one contains more content than the other, so it creates a scroll bar to the right of your browser. The scroll bar makes my body move a tad bit to the left because it's centered. How can I prevent this using only html and css? (no scripts)

有帮助吗?

解决方案

body {
   overflow-y: scroll;
}

That will force the scrollbar container to be always visible, even when there's no scrollbar, keeping your content centered.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top