如果没有内联定义或者为其添加CSS样式规则,input元素默认的大小为"20"。
那么如何将默认值设置为实际值呢?对于其他元素:
<div style="display: inline; width: auto;">
The box will only fit the width of it's content
</div>
只需使用width: auto即可。我无法设置定义的宽度,因为值可能会更长。例如:
<input id="short" type="text" value="1000" />
<input id="long" type="text" value=" Areally long name is in this input field." />
我想让 #short 的大小为 1000(实际上是 size="4" 加上 padding),但 #long 的长度应为所需长度。这些输入是以编程方式传入的,因此我不能简单地在想要缩短的输入上放置 short 类,并在想要长的输入上放置 long 类。我真的只想这样做:input { width: auto; }
有没有办法做到这一点?