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

后端 未结 11 511
被撕碎了的回忆
被撕碎了的回忆 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:49

    Wrap all the elements in a div, make that div position relative and overflow hidden. It solves this problem every time. :D

    0 讨论(0)
  • 2020-12-31 07:50

    Your body is not set to relative.

    0 讨论(0)
  • 2020-12-31 07:50

    Old question I know, but may help someone else out. The below expands on James response but works in IE6/7/8/9, FF and Webkit. Yes it uses evil expressions but you can put that in a IE6 specific stylesheet.

    #bodyInner {
           width: 100%;
           min-width: 960px;
           overflow: hidden;       
           width:expression(((document.compatMode && document.compatMode=='CSS1Compat') ? document.documentElement.clientWidth : document.body.clientWidth) > 980 ? "100%" : (((document.compatMode && document.compatMode=='CSS1Compat') ? document.documentElement.clientWidth : document.body.clientWidth) #LT# 980 ? "960px" : "97.5%"));
    }
    
    0 讨论(0)
  • 2020-12-31 07:54

    If the page language is left-to-right, then the left non-fitting elements don't cause a scrollbar.

    Try this:

    <html dir="rtl">...</html>
    

    This will change the text direction of the page to Right-To-Left, and now the left div will cause a scrollbar, not the right one.

    You can do the same with direction:rtl css property.

    If you want your page render to be independent from text direction then you can arrange page elements differently to avoid this.

    0 讨论(0)
  • 2020-12-31 07:56

    Not knowing what you'd like to do with this, I would perhaps set a background image on the body instead.

    0 讨论(0)
提交回复
热议问题