Skip to content

Instantly share code, notes, and snippets.

@gminova
Forked from martynchamberlin/scrollbars.md
Created July 15, 2020 12:19
Show Gist options
  • Save gminova/78cccb4647a8452eadb264b796bce897 to your computer and use it in GitHub Desktop.
Save gminova/78cccb4647a8452eadb264b796bce897 to your computer and use it in GitHub Desktop.

Revisions

  1. @martynchamberlin martynchamberlin revised this gist Mar 24, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion scrollbars.md
    Original file line number Diff line number Diff line change
    @@ -6,7 +6,7 @@ When you _do_ scroll, the width of viewport and the available width of the inner

    If you change the "Show scroll bars" setting to "Always" then the scrollbar takes up a decided amount of width - 16 pixels to be precise.[^1] Let's say your browser height is 300 pixels and your broswer width is also 300 pixels. With this setting, if you toggle the height of the body from 300 to 600, causing scrollableness, then a scrollbar will appear only have you have done the toggle. The width of your body will have gone from 300 to 284 pixels, because the scrollbar takes up space in a way that it did not in the other setting. Interestingly, if you're talking about a Chrome extension, and you've given the extension a width of 300 pixels, with "Always," the extension width becomes 316 pixels. The extension width is generious. It does not eat.

    What if you decide to [force a vertical scrollbar](https://css-tricks.com/snippets/css/force-vertical-scrollbar/) to always appear? In the default Mac setting, this will result in no differene visually or in any other way. It's as if you didn't write the CSS at all. In the "Always" setting, it will result in a scrollbar taking up 16 pixels of width. Back to the extension paradigm, it does eat, too.[^2] If the extension width is set to 300 pixels, with this forced vertical scroll bar, the available space is now 284 pixels.
    What if you decide to [force a vertical scrollbar](https://css-tricks.com/snippets/css/force-vertical-scrollbar/) to always appear? In the default Mac setting, this will result in no difference visually or in any other way. It's as if you didn't write the CSS at all. In the "Always" setting, it will result in a scrollbar taking up 16 pixels of width. Back to the extension paradigm, it does eat, too.[^2] If the extension width is set to 300 pixels, with this forced vertical scroll bar, the available space is now 284 pixels.

    ## How It Works on Windows

  2. @martynchamberlin martynchamberlin revised this gist Mar 17, 2017. 1 changed file with 17 additions and 1 deletion.
    18 changes: 17 additions & 1 deletion scrollbars.md
    Original file line number Diff line number Diff line change
    @@ -1 +1,17 @@
    By default, scrollbars do not appear on Mac except when the user is scrolling. You can double check this by going to System Preferences ->
    ## How It Works on Mac

    By default, scroll bars do not appear on Mac except when the user is scrolling and when there is hidden content. You can double check this by going to System Preferences -> General -> Show scroll bars: Automatically based on mouse or trackpad.

    When you _do_ scroll, the width of viewport and the available width of the inner content does not change from what it was. If the width was 300 pixels, it still is 300 pixels.

    If you change the "Show scroll bars" setting to "Always" then the scrollbar takes up a decided amount of width - 16 pixels to be precise.[^1] Let's say your browser height is 300 pixels and your broswer width is also 300 pixels. With this setting, if you toggle the height of the body from 300 to 600, causing scrollableness, then a scrollbar will appear only have you have done the toggle. The width of your body will have gone from 300 to 284 pixels, because the scrollbar takes up space in a way that it did not in the other setting. Interestingly, if you're talking about a Chrome extension, and you've given the extension a width of 300 pixels, with "Always," the extension width becomes 316 pixels. The extension width is generious. It does not eat.

    What if you decide to [force a vertical scrollbar](https://css-tricks.com/snippets/css/force-vertical-scrollbar/) to always appear? In the default Mac setting, this will result in no differene visually or in any other way. It's as if you didn't write the CSS at all. In the "Always" setting, it will result in a scrollbar taking up 16 pixels of width. Back to the extension paradigm, it does eat, too.[^2] If the extension width is set to 300 pixels, with this forced vertical scroll bar, the available space is now 284 pixels.

    ## How It Works on Windows

    Nobody cares how it works on Windows, but it's still important from a market share standpoint. The width of the scroll bar on windows is 17 pixels. In my testing, everything about how a Windows behaves is exactly how a Mac behaves scroll-wise when "Always" is enabled in System Preferences.

    [^1]: The width of scrollbars for both Mac and Windows were derived by checking the width of the DOM when a scrollbar exists and then checking the width of the DOM when a scrollbar does not exist, and finding the delta between the two. Given that the Chrome inspector rounds numbers to their nearest integer, it very well may be that the actual width is slightly different from these values, but these are the values I got.

    [^2]: I should be careful in saying that. `overflow-y: scroll` to the `html` does not force a scrollbar in an extension. So the only way to force a scrollbar is to perform this on an inner div element. In doing so, it's unsurprising that a scrollbar would result in eating. It's a separate tier scrollbar from the outer scrollbar. If we _could_ force an outer scrollbar perpetually, it would stand to reason that this _not_ eat. But without an ability to test, it's impossible to know for sure.
  3. @martynchamberlin martynchamberlin created this gist Mar 17, 2017.
    1 change: 1 addition & 0 deletions scrollbars.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    By default, scrollbars do not appear on Mac except when the user is scrolling. You can double check this by going to System Preferences ->