o_O*_*o_O 11 html css textbox input css3
默认情况下,input元素是size ="20",如果没有内联定义或者CSS样式规则归因于它.
如何使默认值的实际大小?对于其他元素:
<div style="display: inline; width: auto;">
The box will only fit the width of it's content
</div>
Run Code Online (Sandbox Code Playgroud)
width:auto就是你所需要的.我不能放置一个定义的宽度,因为该值可能更长.例如:
<input id="short" type="text" value="1000" />
<input id="long" type="text" value=" Areally long name is in this input field." />
Run Code Online (Sandbox Code Playgroud)
我希望#short的大小为1000(基本上大小="4"+填充),但#long只要需要.这些输入是以编程方式进行的,所以我不能简单地在我想要的短片上写一个简短的课程,而在我想要的那个片段上放一个长课.我真的很喜欢它,如果我可以把:
input { width: auto; }
Run Code Online (Sandbox Code Playgroud)
无论如何要做到这一点?
小智 8
默认情况下输入元素是size ="20"
此"默认大小"取决于浏览器,版本和操作系统.在内联样式中无法执行此操作.
最好的解决方案是设置宽度和填充,使其总和达到100%
input {
width: 98%;
padding: 1%;
}
Run Code Online (Sandbox Code Playgroud)
然后将其设置为绝对左右0
<fieldset>
<input type="text" />
</fieldset>
Run Code Online (Sandbox Code Playgroud)
最后添加这个CSS
<style type="text/css">
fieldset {
position: relative;
}
input {
position: absolute;
left: 0;
right: 0;
}
</style>
Run Code Online (Sandbox Code Playgroud)
“你如何使默认值成为实际大小?(...)如果我可以输入: input { width: auto; } 无论如何要做到这一点,我真的很喜欢它?”
在Input HTML Element 中,width由其size属性控制。这是我用来模拟的一种快速方法{ width: auto; },它是浏览器依赖性证明:
<input type="text" [size]="element.value.length + 1" #element>
Run Code Online (Sandbox Code Playgroud)