Brian's Blog

items I see across my tribes

Force Vertical Scrollbar

November 13
by briancarter 13. November 2011 13:16
html {
       overflow-y: scroll;
}

This is invalid CSS, but it works in everything except Opera. The reason for this is to prevent "centering jumps" when navigating back and forth between pages with enough content to have a vertical scroll bar and pages that do not.

Another solution that works well in all widely used browsers with only a few lines of code, the document height will always be at least one pixel longer.

html, body {
  height: 100%;
  margin: 0 0 1px;
  padding: 0;
}

I typically use them both.  Avoids the ugly bouncing when going from page to page or when AJAX loading a div.

Categories:


 Questions or Feedback, my contact information is located on my About page.


The opinions, thoughts, and comments made in these blog posts are solely my own (unless otherwise stated). They do not reflect the opinions, thoughts or practices of my employer, my universities, my family, or anyone else. Also, I retain the right to change my mind about anything I publish here without having to go back and edit posts that occurred in the past. 

These are my opinions, or just as likely, someone else's opinions that I leveraged for my own.