100vw may not fit in the browser window
To create a block on this page that covers the
full width of the browser window I set the CSS width to 100vw
. Since
1 vw represents 1 % of the width of the
browser window I assumed 100vw
would match the full width.
Not quite.
In this case the block was too wide, which caused a horizontal scrollbar to appear in Firefox on Windows.
The cause for this situation is that the
base for calculating
the width of 1 vw is the viewport, even if part of it is already in use
by a scrollbar. So, 100vw
does not represent the available space for page content, but
width of the browser window.
The suggestion to include the scrollbar when overflow:scroll
is set on the body, in
the calculation, was
rejected.
For most visitors this is not problem. On mobile phones a scrollbar is overlaid on the window, which means it does not reduce the size of the window.
On Windows, scrollbars do take up space. That space is taken from the available space for the page.
If you are sure no verical scrollbar will appear on a page, 100vw
will fit.
Otherwise, use a different solution, for example a width of 100%
.