Problem with position: relative when IE6/IE7 window resized RRS feed

  • 질문

  • I'm using a <div> tag that has position: relative as a container for an <img> and several <a> tags that have position: absolute.  That is, I'm establishing the parent <div> tag as the positioning context for its <img> and <a> children.

    I "center" the parent <div> using margin: auto and an explicit width.  When the browser window is resized, IE6 and IE7 fail to re-center the parent <div> and its children. You must refresh the browser window first.  IE8, FF 3.5 (etc) re-center the parent div+children when the window is resized.

    How can I workaround this in IE6 (and especially) IE7?  I wrote some JS to do a refresh (from local cache) of the page on the resize event if the browser is IE6/7, but that's not a great solution.

    I can't change the parent <div> tag to position: static, because then its children (which mush have position: absolute) position themselves in relation to the <body> tag. And I've tried inserting an "intermediate" <div> tag between the current parent <div> and its children, to see if that would help (it doesn't).



    PS: who came up the names "absolute" (to mean relative to its positioning context) and "relative" (to mean the normal position the browser will choose)? Seems like "relative" and "normal" would have been much better choices...but I'm probably not the first to mention this.       


    2010년 2월 10일 수요일 오후 10:22


모든 응답

  • I found the problem.

    It's a bug in IE6 and IE7.

    The workaround is to add position: relative to the <body> tag

    See: http://friendlybit.com/css/ie6-resize-bug/

    • 답변으로 표시됨 dthouston 2010년 7월 12일 월요일 오후 2:52
    2010년 2월 11일 목요일 오후 6:40
  • Thanks, I just used this to solve the same problem will the centering being fixed in ie7.

    Absolute means to start at the same place every time. That is, the action is not affected by other things that are happening. It could be the top of the page or the top of a tag, but it will always start at the same place. In other words, if you start counting will absolutely get to the same place every time no matter what everything else is doing.

    Relative means to start from wherever you happen to be at the time. So, if you start counting the ending place will depend on where you where when you started. That is, where you end up is relative to where you started.

    2011년 1월 15일 토요일 오후 2:05