position: fixed caused element to be wider than browser

前端 未结 6 2691
独厮守ぢ
独厮守ぢ 2021-02-20 13:04

Can anyone tell me why position:fixed cause the element to be wider than the browser or other content on the page and causing horizontal scrolling?

Here is the code HTML

6条回答
  •  刺人心
    刺人心 (楼主)
    2021-02-20 14:01

    I was having a similar problem only on mobile. Despite having no margins, borders, padding on any of the parents, my fixed element was still wider than the viewport, and I didn't have the option of using width: auto.

    If you're willing to not support IE8 and below, you can use

    width: 100vw
    

    Can I use Viewport units: vw, vh, vmin, vmax

提交回复
热议问题