Bug Tracker

Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#13384 closed bug (notabug)

$().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:
Blocked by: Blocking:


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 (4)

comment:1 Changed 4 years ago by dmethvin

Resolution: notabug
Status: newclosed

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 4 years 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 4 years ago by mikesherov

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

comment:4 Changed 4 years ago by mikesherov

Documentation has been updated and will go live shortly.

Note: See TracTickets for help on using tickets.