Skip to main content

Bug Tracker

Side navigation

#4296 closed bug (fixed)

Opened March 05, 2009 07:53AM UTC

Closed June 12, 2010 01:29PM UTC

Last modified June 15, 2012 03:17PM UTC

css('font-size) converts percentage to pixels in IE

Reported by: Kwooda Owned by:
Priority: major Milestone: 1.4
Component: attributes Version: 1.3.1
Keywords: Cc:
Blocked by: Blocking:
Description

A span that inherits its font size from a CSS rule set on the BODY tag that is set to 62.5% causes jQuery's css('font-size') call to return 625px. My assumption is that either jQuery or IE is some converting the percentage to a pixel value. I have not tried this with other values.

body { font-size:62.5%; }

Attachments (0)
Change History (6)

Changed March 18, 2009 07:36AM UTC by Kwooda comment:1

Here is a bit of code I am using to get the font size in pixels in IE:

    if (elem[0].currentStyle) {
        var d = j$('<div/>').css({position:'absolute',top:0,left:0,height:'1.0em',visibility:'hidden',lineHeight:'1.0em'}).text('M').appendTo(elem),
            size=d[0].style.pixelHeight+px;
        d.remove();
    }

It should work in all cases regardless of what units font size is specified in. The problem with Dean Edwards' hack is that font size defines the height of the font, and his hack was using a technique to interpolate that from a width value that didn't take into account percentage values.

Note that in the hack I provided, above, I create a test div and attach it to the element so the div inherits the font size of the element. If it is not safe to blindly attach the div to just any element, some logic may be needed to test for that and perhaps append to the element's parent, instead, in fringe cases. The problem is, if you attach the test div to the element's parent, it will not pick up the correct font size if the style applied directly to the element specifies a font size.

  • William Hubbard

Changed July 07, 2009 03:26PM UTC by mic030 comment:2

I ran into this one as well. Thank you very much for the workarround!

Hope this well be fixed in the next version. Keep up the great work!

Cheers,

Michael

Changed September 01, 2009 02:58AM UTC by haruka comment:3

Changed June 12, 2010 01:29PM UTC by dmethvin comment:4

component: unfiledattributes
resolution: → fixed
status: newclosed

Should have been fixed by the commit for #760 in 1.4; reopen if the problem persists.

Changed June 15, 2012 03:14PM UTC by elwayman02@gmail.com comment:5

I'm still seeing this issue in jQuery 1.7.1 on IE 8.

Changed June 15, 2012 03:17PM UTC by elwayman02 comment:6

Replying to [comment:5 elwayman02@…]:

I'm still seeing this issue in jQuery 1.7.1 on IE 8.

Sorry, I should have been more specific. This issue is persistent across multiple attributes...I have not tested for font-size specifically. Perhaps I should log a separate issue for the other attributes, although I assumed that the fix would be for all uses of .css(), not just font-size.