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.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…