Try the following simple example:
<html>
<head>
<style>
div,
input {
border: 1px solid #000;
margin: 2px;
padding: 3px;
width: 100px;
}
</style>
</head>
<body>
<div>div</div>
<input value="input" />
</body>
</html>
Notice the div and the input gets different widths. In fact, the width of the input is 92px. For the input, Firefox calculates the width outside the border and padding, the same way IE does for everything. Shouldn't it treat input elements the same as everything else, and add the padding and border to the width?
As phihag says, it's block vs inline.
However, a flaw with your example: you're not using a DOCTYPE.
That means the browser is free to render as it sees fit.
Stick
<!DOCTYPE html>
at the top to use the nice and compact HTML5 DOCTYPE, which will prevent browsers from going into Quirks Mode.The width issue is a result of brain-dead IE-compatible quirks mode. See Peter Boughton's answer(doctype) for remedy.
Additionally,
div
is a block-level element, butinput
isn't. Adddisplay:block;
to your rule to achieve the div rendering in both cases, ordisplay:inline;
to format both elements as inline. However, Firefox will forgive top-level inline elements and render them appropriately.