Bug Tracker

Ticket #13384 (closed bug: notabug)

Opened 23 months ago

Last modified 22 months ago

$().height() or $().width() sets wrong value on elements with "box-sizing: border-box"

Reported by: t.nowakowski@… Owned by:
Priority: undecided Milestone: None
Component: unfiled Version: 1.9.0
Keywords: Cc:
Blocking: Blocked by:

Description

When i use $().height() or $().width() on element with "box-sizing: border-box" the new value is increased by the padding and border.

Let's say we have element foo: #foo {

border: 1px solid red; padding: 4px 0; box-sizing: border-box;

} If i run this code: $("#foo").height(10) element height would be set to 20px (10+4+4+1+1).

working example here:  http://jsfiddle.net/ztcj2/3/

This bug is also present in 1.8.x version. In earlier release it works fine.

Tested in latest firefox, chrome, opera editions and IE9.

Change History

comment:1 Changed 23 months ago by dmethvin

  • Status changed from new to closed
  • Resolution set to notabug

To maintain sanity, the .height() is always the content height. It doesn't change based on CSS properties kept in some distant file. The other height methods like .innerHeight() are setters so you can choose which height you mean in your code without ambiguity.

Note that .height() will always return the content height, regardless of the value of the CSS box-sizing property. --  http://api.jquery.com/height/

comment:2 Changed 22 months ago by jhogervorst

The documentation says otherwise:

Note that .height(value) sets the height of the box in accordance with the CSS box-sizing property. Changing this property to border-box will cause this function to change the outerHeight of the box instead of the content height.

Source:  http://api.jquery.com/height/

comment:3 Changed 22 months ago by mikesherov

jhogervorst, thanks for noticing that! The documentation is wrong. Fixing now.

comment:4 Changed 22 months ago by mikesherov

Documentation has been updated and will go live shortly.

Note: See TracTickets for help on using tickets.