IE7 relative/absolute positioning bug with dynamically modified page content

前端 未结 3 1054
粉色の甜心
粉色の甜心 2020-11-28 06:02

I was wondering if there\'s anyone having an idea how to tackle with the following problem in IE7:



        
相关标签:
3条回答
  • 2020-11-28 06:15

    This is related to the "hasLayout bug" of IE. The relatively positioned #panel parent doesn't have layout and hence IE forgets to redraw its children when it get resized/repositioned.

    The problem will go if you add overflow: hidden; to the relatively positioned #panel parent.

    #panel { position: relative; overflow: hidden; border: solid 1px black; } 
    

    In depth background information about this IE bug can be found in the excellent reference "On having layout" and then for your particular problem specifically the chapter "Relatively positioned elements":

    Note that position: relative does not trigger hasLayout, which leads to some rendering errors, mostly disappearing or misplaced content. Inconsistencies might be encountered by page reload, window sizing and scrolling, selecting. With this property, IE offsets the element, but seems to forget to send a “redraw” to its layout child elements (as a layout element would have sent correctly in the signal chain of redraw events).

    The overflow property triggers the element to have layout, see also the chapter "Where Layout Comes From":

    As of IE7, overflow became a layout-trigger.

    0 讨论(0)
  • 2020-11-28 06:22

    I have created my function to trigger redraw. Maybe it is not a right solution, but it works.

    // Script to fix js positon bug on IE7
    
    // Use that function, recomended delay: 700
    function ie7fixElementDelayed(elements, delay) {
        window.setTimeout(
            function () {
                if(navigator.appVersion.indexOf("MSIE 7.") != -1) {
                    ie7fixElement(elements);
                }
            },
            delay
        );
    }
    
    function ie7fixElement(elements) {
        elements.each(function(i) {
            var element = $(this);
            var orginalDisplayValue = element.css("display");
    
            element.css("display", "none");
            element.css("display", orginalDisplayValue);
        });
    }
    

    Sample usage:

    ie7fixElementDelayed($('#HandPickedWidget .widget'), 700);
    
    0 讨论(0)
  • 2020-11-28 06:25

    This solution doesn't necessarily have anything to do with dynamic content, but it worked for me (at least made the page borked to a manageable degree): specify dimensions. I only noticed IE7 thought a div didn't have a width when using the crappy 'Select element by click' tool (ctrl+B) in IE tools.

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