Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Force IE to 'redraw' an element with JavaScript to fix CSS bug?

Im experiencing an IE bug. The CSS counter property doesn't work in IE9 for elements that are hidden on page load (eg tabs).

css counter not working in internet explorer for hidden content - how to fix?

As I posted above, I've been able to fix this by setting some inline CSS with JavaScript. I set padding-left to 0 (even though the element already had no left padding) when its unhidden. This makes IE 'redraw' the element and the CSS is then applied correctly.

This isn't and ideal solution however. If the design changed to have left padding on the element then my JavaScript fix would break the layout. What other method can I use to make IE 'redraw' the element? Is there a standard way to do this?

like image 398
Evanss Avatar asked Oct 13 '15 15:10

Evanss


1 Answers

Paul Irish has compiled a list for you

What forces layout / reflow. The comprehensive list.

All of [the properties or methods found at this link], when requested/called in JavaScript, will trigger the browser to synchronously calculate the style and layout*. This is also called reflow or layout thrashing, and is common performance bottleneck.

I don't want to post the entire list here to avoid plagiarizing, since I am essentially adding nothing to the answer; I am simply pointing you to it.

However, I will say that while Paul Irish warns that using these is a "common performance bottleneck", they can be used strategically to force reflow when desired. This is especially useful in browser-specific scenarios.

If you want to limit the reflow to just IE9, you will want to wrap your layout-thrashing calls inside a feature detection check.

like image 106
gfullam Avatar answered Oct 05 '22 22:10

gfullam