I have this page which contains a centered div, this div contains a button. You click the button and a drop-down list will come out.It’s a very common feature.
But I found a strange problem.
When you click the drop-down list becomes visible, the whole div moves left for like 10px, and moves back when the list disappears.
This seems stupid and I spend a lot of time on finding what happened.
As everybody can predict, the reason is as stupid as the problem.
That’s because of the scrollbar of body element.
By default, the scrollbar is invisible because the body height is less than your screen height, it becomes visible as the body height increases. In my case, the drop-down list has a very huge height which is bigger than the browser’s height.
This will cause a decrease of page width, so all elements in the div move left because this div is centered.
The solution is make the scrollbar always visible and only active when needed.
CSS code will go like that:
html {overflow: -moz-scrollbars-vertical; overflow-y: scroll; }
as far as I know, no site did that, except Google homepage.
btw:
You can test this using Developer Tools:
1st Pin Debug window to bottom.
2nd Browse Google and Bing and turn Developer Tools to change body height.

