How do I force a vertical scrollbar to appear?

CssMargin

Css Problem Overview


My site has both very short and longer pages. Since I center it in the viewport with margin: 0 auto, it jumps around a few pixels when switching from a page that has a scrollbar to one that hasn't and the other way around.

Is there a way to force the vertical scrollbar to always appear, so my site stays put when browsing it?

Css Solutions


Solution 1 - Css

Give your body tag an overflow: scroll;

body {
    overflow: scroll;
}

or if you only want a vertical scrollbar use overflow-y

body {
    overflow-y: scroll;
}

Solution 2 - Css

html { overflow-y: scroll; }

This css rule causes a vertical scrollbar to always appear.

Source: http://css-tricks.com/snippets/css/force-vertical-scrollbar/

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionBakabakaView Question on Stackoverflow
Solution 1 - CssJohn CondeView Answer on Stackoverflow
Solution 2 - CssBakabakaView Answer on Stackoverflow