JSFiddle - React, Tailwind, and code Playground

Remove Scrollbar Jumping

by Jennifer Perrin

HTML

<link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.1/css/bootstrap.css">
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css">
<script src="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.1/js/bootstrap.min.js"></script>
<div class="container">
    <h1 class="text-center">Remove Scrollbar &quot;Jumping&quot;</h1>
    <p class="lead text-center">When centering a page with CSS like <code>margin:auto;</code>, there's a small gotcha: the page will "jump" a little on certain browsers when navigating between short and long pages. This is because the scrollbar gets hidden with short pages and is shown again with longer pages, which makes the page move a little horizontally.</p>
</div>

CSS

@import url(http://fonts.googleapis.com/css?family=Dosis);

html {
    /* THE TRICK */
    margin-left: calc(100vw - 100%);
    overflow: auto;
}

body {
    padding: 10px 50px;
    font-family: "Dosis", sans-serif;
    background: #f0f0f0;
    color: #555555;
}

JavaScript

// Bootstrap v3.3.1
// Font Awesome 4.2.0