Bug Tracker

Modify

Ticket #4296 (closed bug: fixed)

Opened 4 years ago

Last modified 12 months ago

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:
Blocking: Blocked by:

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

Change History

comment:1 Changed 4 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),
            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

comment:2 Changed 4 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!

Cheers,

Michael

comment:3 Changed 4 years ago by haruka

comment:4 Changed 3 years ago by dmethvin

  • Status changed from new to closed
  • Resolution set to fixed
  • Component changed from unfiled to attributes

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

comment:5 follow-up: ↓ 6 Changed 12 months ago by elwayman02@…

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

comment:6 in reply to: ↑ 5 Changed 12 months ago by elwayman02

Replying to 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.

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.