Skip to content
This repository has been archived by the owner on Jan 28, 2023. It is now read-only.

Scrollbar width not handled? #13

Open
tbredin opened this issue Jan 25, 2021 · 1 comment
Open

Scrollbar width not handled? #13

tbredin opened this issue Jan 25, 2021 · 1 comment

Comments

@tbredin
Copy link

tbredin commented Jan 25, 2021

The window width this tool reports is not correct when a scrollbar is present.

eg: I am seeing width: 753 when my browser is actually 768 px wide, showing my >767px lg layout from my css, but still reporting incorrectly as md by this utility because it is not considering media queries (which include scrollbar width).

Looks like its querying the inner width rather than including the scrollbar in its calculations. CSS media queries will measure your screen including the scrollbar.

Testing in Chrome 87.0.4280.141

@tbredin tbredin changed the title Scrollbar handling Scrollbar not handled? Jan 25, 2021
@tbredin tbredin changed the title Scrollbar not handled? Scrollbar width not handled? Jan 25, 2021
@tbredin
Copy link
Author

tbredin commented Jan 25, 2021

Possible workaround:

// hide the scrollbar on the body
body {
    overflow: hidden;
}

// requires a div container around your app to handle the scroll  
body > div {
    overflow-y: auto;
    overflow-x: hidden;
    height: 100vh;
    // unsure if this is really needed (see comment below)
    -webkit-overflow-scrolling: touch;
}

This will work because the scrollbar you'll now see is on the inner div, whereas the body is always the full width of the browser so matching the equivalent CSS media query.

I haven't tested this thoroughly yet, and from memory it might have issues on some touch devices that need -webkit-overflow-scrolling: touch; on scroll containers to reproduce their momentum scrolling behaviour.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant