Scrollbar Width Hack

Have you ever wanted to line something up with the right side of the content of an element with a scrollbar, but were frustrated because scrollbar widths vary by browser (including mobile ones where they might not be visible)? Yeah, me too. I just made a demo page of a hack for that. It creates an invisible element with a scrollbar on it for positioning.  This seems to do what I need right now.  What would be the best, but I don’t have an answer for, is a way to do something like this only taking into account whether the visible element with the scrollbar has a scrollbar or not.  My solution is to make sure it always does.  Doing the same thing when it might not is the next question.  I can think of a couple of ways to do this with JavaScript, but I wanted to do it with CSS.

One thought on “Scrollbar Width Hack

Leave a Reply

Your email address will not be published. Required fields are marked *