#13384 closed bug (notabug)
$().height() or $().width() sets wrong value on elements with "box-sizing: border-box"
Reported by: | Owned by: | ||
---|---|---|---|
Priority: | undecided | Milestone: | None |
Component: | unfiled | Version: | 1.9.0 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
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 (4)
comment:1 Changed 10 years ago by
Resolution: | → notabug |
---|---|
Status: | new → closed |
comment:2 Changed 10 years ago by
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 10 years ago by
jhogervorst, thanks for noticing that! The documentation is wrong. Fixing now.
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.