#1084 ✓resolved
Viktor Kojouharov

Absolutely positioned, hidden block elements are not sized correctly

Reported by Viktor Kojouharov | June 28th, 2010 @ 09:51 AM

With 1.7, when calling Element#getDimensions on an absolutely positioned, hidden block element, with width set to auto, it returns incorrect dimension.

Since it is absolutely positioned, the element will wrap around its contents. In 1.6, prototype did not make any assumptions about the size, and just returned the 'correctly' calculated width by the browser. In 1.7, prototype specifically expects a width to be set beforehand, or it will take the parent's width as its own:


IMHO, there should probably be a third 'else if', which checked whether the element is absolute, is block and has no width, and in that case, it should return the positionedWidth.

Comments and changes to this ticket

  • Viktor Kojouharov

    Viktor Kojouharov July 10th, 2010 @ 12:34 AM

    The attached patch provides a test case and a fix, which has been tested under FF3.6 and Chromium 6 under Linux

  • Andrew Dupont

    Andrew Dupont August 15th, 2010 @ 02:53 AM

    • Assigned user set to “Andrew Dupont”
    • Tag changed from 1.7 layout dimensions to layout
    • Importance changed from “” to “Low”

    Don't think we can use that patch. The call to getPixelValue used to look like that, but it was changed to deal with percentage units (which can be returned from a getComputedStyle call). See #1040.

    Can you modify the patch to prevent that regression?

  • Viktor Kojouharov

    Viktor Kojouharov August 15th, 2010 @ 04:30 PM

    I don't understand what the problem is. getPixelValue can still receive only one parameter, and it treats that parameter as if it was obtained from a style property of the element. Can you elaborate on your comment, please?

  • Viktor Kojouharov

    Viktor Kojouharov August 15th, 2010 @ 04:35 PM

    If I understood correctly, the problem comes from 'fixed' elements in in IE, where the width was in percentage, is that it? Then the modified patch should fix it, since it is calling the function with the obtained context.

  • GitHub Robot

    GitHub Robot August 23rd, 2010 @ 12:01 AM

    • State changed from “new” to “resolved”

    (from [c814fb7bb4c3e025f90cb08622a8fe74e3fbf646]) Ensure hidden absolutely-positioned elements are sized correctly when they have no explicit width set. [#1084 state:resolved] (Viktor Kojouharov, Andrew Dupont) http://github.com/sstephenson/prototype/commit/c814fb7bb4c3e025f90c...

  • Andrew Dupont

    Andrew Dupont August 23rd, 2010 @ 12:05 AM

    You understood correctly. For both absolute- and fixed-position elements, a getComputedStyle call can return a percentage value instead of a pixel value. (Returning a pixel value in such cases would be misleading, since that pixel value could change when the window resizes.) For that reason, getPixelValue has that second method signature — to interpret that percentage requires both the element and its positioning context.

    Thanks for the patch!

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

The Prototype JavaScript library.

Shared Ticket Bins



Referenced by