Bug Tracker

Opened 14 years ago

Closed 12 years ago

Last modified 10 years ago

#4296 closed bug (fixed)

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:


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%; }

Change History (6)

comment:1 Changed 14 years ago by Kwooda

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),

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

comment:2 Changed 13 years ago by mic030

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!



comment:3 Changed 13 years ago by haruka

comment:4 Changed 12 years ago by dmethvin

Component: unfiledattributes
Resolution: fixed
Status: newclosed

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

comment:5 Changed 10 years ago by [email protected]

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

comment:6 in reply to:  5 Changed 10 years ago by elwayman02

Replying to [email protected]:

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.

Note: See TracTickets for help on using tickets.