box-sizing-polyfill
box-sizing-polyfill copied to clipboard
boxsizing.htc causes page elements in IE7 to shrink
I have been experiencing a problem with page elements in IE7 shrinking inward from left and right when I use boxsizing.htc for border-box sizing of my float-based layouts.
Here is a similar report: Strange interaction with box-sizing-polyfill when window resized
(Sorry about all the closing and reopening of my issue. I thought the polyfill was working and then it wasn't.)
I tried using boxsizing.htc for only the necessary elements (rather than global *) as advised my Schepp ( https://github.com/Schepp/box-sizing-polyfill/issues/12 ) but still experience shrinking in IE7 when I include this class (some .page's also include padding):
.page { background-color:white; border:1px #6666FF solid; color:#000099; font-family:Helvetica, Arial, sans-serif; line-height:1.5; margin:0.625em auto; width:60em; }
As an alternative, I am getting good results for my float-based layouts using a simple jQuery script to adjust the box widths for the necessary elements:
/* Set border-box widths for IE6 and 7 */
$(function() { var selectors = [ '.page', '#header-1', '#header-2', '#home-1', '#home-2', '#plan-refs-1', '#plan-refs-2' ];
$(selectors).each(function(i)
{
var selector = selectors[i];
var content_width = $(selector).width();
var border_width = $(selector).outerWidth();
if (content_width)
{
var new_content_width = content_width - (border_width - content_width);
$(selector).css("width", new_content_width);
}
});
});
I was getting this problem when I was adding/removing a class on focus/blur, that was triggering the checkPropertyChange()
function, which seems to cause the shrinking problem.
If the elements you will use the behaviour on will only ever be static (i.e. no bound events that could cause border/padding/content width changes) then you can somewhat safely remove the following line to remove the event binding:
<attach event="onpropertychange" onevent="checkPropertyChange()" />
Very limited fix of course because the width won't be updated to match elements changes, but it suited my needs.