Bug Tracker

Opened 7 years ago

Closed 7 years ago

#10595 closed bug (invalid)

Selectbox width() and css('width') discrepancies

Reported by: Adam Owned by:
Priority: low Milestone: None
Component: css Version: 1.6.4
Keywords: Cc:
Blocked by: Blocking:

Description

See JS fiddle at: http://jsfiddle.net/8MW4u/3/

CSS: width: 100px border: 1px padding: 5px

The jQuery width() method incorrectly subtracts the borders width (2px) of a 100px width selectbox in Chrome, reporting the width as 98px instead. This does not happen with an input field of type text with the exact same CSS.

In Firefox the discrepancy is even worse, since there the padding is also subtracted, reporting a width of 88px. Again, for a text input everything works fine.

The exact same problem occurs with css('width'), which reports the same values.

Why are the reported widths of a selectbox not consistent with the reported widths of a text input? And why not cross-browser consistent at least?

Change History (1)

comment:1 Changed 7 years ago by timmywil

Component: unfiledcss
Priority: undecidedlow
Resolution: invalid
Status: newclosed

This is due to a combination of the nature of the box model and the different default styles for select boxes and inputs. What you are retrieving is the real and correct _computed_ values, even if they are different across browsers. To unify them, all of the necessary css properties need to match across browsers in order to get the same behaviors.

Something like this: http://jsfiddle.net/timmywil/8MW4u/6/

Note: See TracTickets for help on using tickets.