Why are horizontal scroll bars shown on my website?

后端 未结 2 889
太阳男子
太阳男子 2020-12-04 02:14

I am making a website and a horizontal scroll bar shows. Of course, I can use overflow-x and that will fix all my problems, but I want to know the origin of the

相关标签:
2条回答
  • 2020-12-04 02:56

    Note that you have your <p> elements relatively positioned and shifted right with right: -450px.

    With position: relative the original space for the element is reserved. So while you're shifting the element rightward 450px, its original space in the layout is kept intact, and the document is lengthened horizontally. That's the reason for the scrollbar.

    Remove or adjust the right: -450px rule to see the difference.

    Also, simply for contrast, switch relative with absolute positioning, which removes the element from the document flow, and the original space is eliminated.

    Read more about CSS positioning at MDN.

    0 讨论(0)
  • 2020-12-04 03:03

    I'd point to this.

    p{
        ...
        position: relative;
        right: -450px;
        ...
    }
    
    0 讨论(0)
提交回复
热议问题