100vw Causing Unexpected Horizontal Overflow
When assigning a width of 100vw to an element, you might expect it to occupy the full viewport width without causing any overflows. However, under certain circumstances, horizontal scrollbars can appear despite using 100vw.
Consider the following example:
html, body { margin: 0; padding: 0; } .box { width: 100vw; height: 100vh; } <div class="box">Screen 1</div>
In this scenario, the .box element will fill the screen without any scrollbars. However, if you add a second .box element below the first one:
<div class="box">Screen 1</div> <div class="box">Screen 2</div>
You will observe the appearance of not only vertical scrollbars (expected) but also a slight horizontal scrollbar.
The reason for this behavior lies in the way 100vw is interpreted by browsers. While it does mean "100% of the viewport width," it represents the visible portion of the viewport that remains after taking into account any scrollbar thickness. In this case, the presence of a vertical scrollbar reduces the available viewport width, which can cause the second .box element to overflow horizontally.
To resolve this issue, you can use max-width: 100% on the .box element:
.box { width: 100vw; height: 100vh; max-width: 100%; }
This will ensure that the element never exceeds the true viewport width, effectively preventing any potential horizontal overflow.
The above is the detailed content of Why Does `100vw` Sometimes Cause Unexpected Horizontal Overflow?. For more information, please follow other related articles on the PHP Chinese website!

If you’ve recently started working with GraphQL, or reviewed its pros and cons, you’ve no doubt heard things like “GraphQL doesn’t support caching” or

In this article we will be diving into the world of scrollbars. I know, it doesn’t sound too glamorous, but trust me, a well-designed page goes hand-in-hand

The Svelte transition API provides a way to animate components when they enter or leave the document, including custom Svelte transitions.

How much time do you spend designing the content presentation for your websites? When you write a new blog post or create a new page, are you thinking about

With the recent climb of Bitcoin’s price over 20k $USD, and to it recently breaking 30k, I thought it’s worth taking a deep dive back into creating Ethereum

npm commands run various tasks for you, either as a one-off or a continuously running process for things like starting a server or compiling code.

I was just chatting with Eric Meyer the other day and I remembered an Eric Meyer story from my formative years. I wrote a blog post about CSS specificity, and

The article discusses using CSS for text effects like shadows and gradients, optimizing them for performance, and enhancing user experience. It also lists resources for beginners.(159 characters)


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 English version
Recommended: Win version, supports code prompts!

SublimeText3 Chinese version
Chinese version, very easy to use

WebStorm Mac version
Useful JavaScript development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

SublimeText3 Linux new version
SublimeText3 Linux latest version