[英]Form elements have same width but are not showing aligned
I have the following two form fields. 我有以下两个表单字段。 They have the same width so they should be displayed aligned and they do so except for Google Chrome. 它们具有相同的宽度,因此它们应该显示为对齐,并且除了谷歌浏览器之外它们也是如此。 In Google Chrome, the textarea has a little more width. 在谷歌浏览器中,textarea的宽度略高一些。 Please help me out in fixing it. 请帮我修理它。 Thanks 谢谢
<input name="phone" type="text" id="phone" style=" font-family: Verdana; color:#FFFFFF; font-size: 13px;background-color: #0E0E0F; border: 1px solid #740086; width:385px; margin-bottom:10px;" size="38" value="Phone #" onfocus="if(this.value==this.defaultValue)this.value='';" onblur="if(this.value=='')this.value=this.defaultValue;"/>
<textarea
name="message"
cols="38"
rows="12"
id="message"
style="font-family:Verdana; color:#FFFFFF; font-size:13px; background-color:#0E0E0F; border:1px solid #740086; width:38px; margin-bottom:10px;overflow:hidden;"
onFocus="if(this.value==this.defaultValue)this.value='';"
onBlur="if(this.value=='')this.value=this.defaultValue;">
Message
I suspect that 38px in the style for the textarea
element is a typo and should be 385px, otherwise you would the area as narrow on all CSS-enabled browsers. 我怀疑textarea
元素的样式中的38px是一个拼写错误,应该是385px,否则你将在所有支持CSS的浏览器上缩小该区域。 And I suspect that in the real code, there is something that causes a line break between the input
and textarea
elements; 我怀疑在实际代码中,有一些东西导致input
和textarea
元素之间的换行; otherwise it is difficult to compare their widths. 否则很难比较它们的宽度。
The reason why the textarea is slightly wider on Chrome is that by the browser stylesheet for WebKit-based browsers , textarea
elements have 2px padding. textarea在Chrome上略宽的原因是, 基于WebKit的浏览器的浏览器样式表 , textarea
元素有2px填充。 You can see this if you use the Inspect element tool of Chrome (via right-clicking) and view “Metrics” there. 如果您使用Chrome的Inspect元素工具(通过右键单击)并在那里查看“指标”,则可以看到此信息。
The apparent solution is then textarea { padding: 0; }
然后明显的解决方案是textarea { padding: 0; }
textarea { padding: 0; }
. textarea { padding: 0; }
。 But since the padding is actually useful, it might be better to set 但由于填充实际上很有用,因此设置可能更好
textarea, input { padding: 2px; }
You seem to be sizing the input element using the size
attribute and using cols
in your textarea. 您似乎使用size
属性调整input元素的size
并在textarea中使用cols
。
You also are defining two styles: width:385px
and width:38px
(the inequality is probably your problem). 您还正在定义两种风格: width:385px
和width:38px
(不平等可能是你的问题)。 I'm not sure which takes precidence ( size
or cols
), but why not avoid confusion and just set equal an width
for both elements and just remove the size
and row
/ col
definitions? 我不确定哪个需要预测( size
或cols
),但为什么不避免混淆,只为两个元素设置相等的width
,只删除size
和row
/ col
定义?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.