HTML5:如何指定文件输入的宽度?

Bri*_*ian 10 css html5

W3C验证器说:"此时元素输入不允许属性大小."

<input type="file" name="foo" size="40" />
Run Code Online (Sandbox Code Playgroud)

在HTML5中指定文件输入宽度的正确方法是什么?

sil*_*uri 10

在输入字段中使用style属性,这允许您使用css.

<input type="file" name="foo" style="width: 40px" />

或者使用单独的css:

input[name="foo"] {
  width: 40px;
}
Run Code Online (Sandbox Code Playgroud)

  • Firefox忽略"宽度"属性.这是我尝试的第一件事. (2认同)

D.A*_*der 5

在您的 css 文件中,指定宽度如下:

input[type=file] { width: 300px; border: 2px solid red; }
Run Code Online (Sandbox Code Playgroud)

http://jsfiddle.net/VbTAV/

  • 我使用的是 Firefox,在您的示例中,实际上是控制宽度的“size”属性(即使不允许),而不是“width”属性。我尝试将示例中的“宽度”更改为 200 或 400,但没有效果。 (2认同)