Absolutely positioned div on right causing scrollbar when the left doesn't

后端 未结 11 624
被撕碎了的回忆
被撕碎了的回忆 2020-12-31 07:02

I\'m trying to \"flank\" a centered div with some design elements that are absolutely positioned outside the main div\'s width. I\'m getting a scroll bar due to the element

11条回答
  •  暖寄归人
    2020-12-31 07:39

    Throwing an overflow-x: hidden on the body tag would work in anything that's not IE6/7... but for those two browsers, you'll need to also add overflow-x: hidden to the html tag.

    So use what you have now with this adjustment:

    html, body { 
            height: 100%; 
            width: 100%;
            margin: 0;
            *overflow-x: hidden;
        }
    
    body { text-align: center; overflow-x: hidden; }
    

    Note that the reason the "*" hack is used in the html, body declaration is because IE8 is unconventional. If you don't use it, IE8 will lose vertical scrollbars as well, not just horizontal. I don't know why. But that solution should be fine.

提交回复
热议问题