Why are horizontal scroll bars shown on my website?

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.

enter image description here

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.

Leave a Comment