Prevent 100vw from creating horizontal scroll

前端 未结 11 2067
不知归路
不知归路 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:48

    An element with width: 100vw only causes horizontal scrollbars when one of it's parents has a horizontal padding. Otherwise it should fit in well.

    Check this fiddle: http://jsfiddle.net/1jh1cybc/ The .parent2 has a padding, which causes the inner .box to break out of it's parent width.

    Edit:

    In your case I guess your body has a margin. Check this fiddle out with you code and try to remove the body css rule: http://jsfiddle.net/1jh1cybc/1/

提交回复
热议问题