position: fixed caused element to be wider than browser

前端 未结 6 2680
独厮守ぢ
独厮守ぢ 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:07

    Because position:fixed behave as the element is detached from document, and placed in the nearest top/left corner of the document, adding default body's margin. That's why it will take the same amount of space, as your second div, if you reset body margin.

提交回复
热议问题