Prevent 100vw from creating horizontal scroll

前端 未结 11 2062
不知归路
不知归路 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条回答
  •  -上瘾入骨i
    2020-12-04 19:44

    Using max-width attribute with width:100vw and it solved my problem.

    Here's what i used.

    .full{
         height: 100vh;
         width: 100vw;
         max-width: 100%;
        }
    

    Basically what it does is it fixes the max width to the viewport so the horizontal scroll gets eliminated.

    More @ https://www.w3schools.com/cssref/pr_dim_max-width.asp

    The max-width property defines the maximum width of an element.

    If the content is larger than the maximum width, it will automatically change the height of the element.

    If the content is smaller than the maximum width, the max-width property has no effect.

提交回复
热议问题