javascript - Elements positioned relatively don't move when the DOM is updated (IE6 and IE7) - Stack Overflow

I have a form with a few fieldsets.One fieldset has a table of time preferences set by the user.The

I have a form with a few fieldsets. One fieldset has a table of time preferences set by the user. The user can add and delete time preferences. When they add a row, a table row is dynamically inserted into the DOM using a jQuery append().

The issue is that in IE6 and IE7 any relatively positioned elements on the page do not "bump" down when the new table rows are added. Furthermore, they don't move when table rows are deleted either. They are kind of just stuck in their spots.

This would be relatively minor, but each fieldset is relatively positioned in order to avoid the IE background overflow issue with fieldsets. Therefore, the form likes quite bad after one adds two or more rows to the table.

Here is the CSS being applied to the fieldsets:

form.pancake fieldset {
    position: relative;
    margin-top: 1.5em;
    padding-top: 1.5em;
}
form.pancake fieldset legend {
    position: absolute;
    top: -0.5em;
    left: 0.5em;
}

When the position: relative is removed from the stylesheet, the dynamically added rows work perfectly and the content moves down as appropriate.

Any help is much appreciated.

I have a form with a few fieldsets. One fieldset has a table of time preferences set by the user. The user can add and delete time preferences. When they add a row, a table row is dynamically inserted into the DOM using a jQuery append().

The issue is that in IE6 and IE7 any relatively positioned elements on the page do not "bump" down when the new table rows are added. Furthermore, they don't move when table rows are deleted either. They are kind of just stuck in their spots.

This would be relatively minor, but each fieldset is relatively positioned in order to avoid the IE background overflow issue with fieldsets. Therefore, the form likes quite bad after one adds two or more rows to the table.

Here is the CSS being applied to the fieldsets:

form.pancake fieldset {
    position: relative;
    margin-top: 1.5em;
    padding-top: 1.5em;
}
form.pancake fieldset legend {
    position: absolute;
    top: -0.5em;
    left: 0.5em;
}

When the position: relative is removed from the stylesheet, the dynamically added rows work perfectly and the content moves down as appropriate.

Any help is much appreciated.

Share Improve this question asked Aug 4, 2009 at 16:08 EthanEthan 1991 gold badge3 silver badges9 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 8

Yeah IE is a real pain when it es to this. I found that I actually had to force it to redraw the DOM element inorder to get it to move. How I did this was to very quickly hide and show the parent object in your case it sounds like the parent to your row. This is not the most elegant solution, but it does the job.

In my case I used jQuery to get the job done.

var forceRedraw = function(obj) {
    /// <summary>Forces a redraw of passed objects.</summary>
    /// <param name="obj" type="jQuery" optional="false">The object for force the redraw on.</param>

    obj = $(obj);

    // force IE to redraw the obj
    if (jQuery.browser.msie) {
        obj.css("display", "none");
        obj.css("display", "block");
    }
};

I recently encountered the same problem. I ended up finding that this only happened when my relatively positioned element was contained within another relatively positioned element.

Although it wasn't possible for me to change the positioning style of the element itself, I was able to remove position:relative from the containing element, and it solved the problem. This might be a good alternative solution, especially on a page with lots of actions that could cause elements to move.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742383490a4433587.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信