为什么 css width 属性 与输入元素一起工作

why css width property is working with input element

根据CSS docs:

The width CSS property ... applies to all elements but non-replaced inline elements, table rows, and row groups

输入是行内元素。那么为什么 width 属性 与 input 元素一起工作?

non-replaced inline elements 除外。输入是替换元素。

Replaced element

In CSS, a replaced element is an element whose representation is outside the scope of CSS. These are kind of external objects whose representation is independent of the CSS. Typical replaced elements are <img>, <object>, <video> or form elements like <textarea> and <input>. Some elements, like <audio> or <canvas> are replaced elements only in specific cases. Objects inserted using the CSS content properties are anonymous replaced elements.

CSS handles replaced elements specifically in some cases, like when calculating margins and some auto values.

Note that some replaced elements, but not all, have intrinsic dimensions or a defined baseline, which is used by some CSS properties like vertical-align.

参考:MDN - Replaced element