Prevent 100vw from creating horizontal scroll

前端 未结 11 2091
不知归路
不知归路 2020-12-04 19:13

If an element is set to width: 100vw; and there is a vertical scrollbar the width of the element will be equal to the viewport plus the width of the scrollbar.<

11条回答
  •  不知归路
    2020-12-04 19:40

    I had the same issue and it was fixed when I added:

    html, body { overflow-y: auto; }
    

    I added the comment:

    /* this fixes a 100vw issue, removing the horizontal scrollbar when it's unneeded */
    

    It works at least with Firefox, Chrome, Opera and Internet Explorer 11 (I used browserling for IE).

    I don't know why it works and if it works in all cases, though.

    EDIT: The horizontal scrollbar disappeared, but I noticed it's still horizontally scrollable using the cursor keys and touch screens...

提交回复
热议问题