是“宽度”适用于文本区域?
CSS 'width'
属性是否适用于
在实践中,人们说他们成功地使用了它,例如使用这样的规则:
textarea
{
width:100%;
}
令我困惑的是CSS 2.1 宽度规范 说,
该属性指定内容 生成的框的宽度 块级和替换元素。 该属性不适用于 不可替换的内联级元素。
我认为 textarea 是一个内联级元素,因为例如像这样的标记......
<p>
This is some more text:
<textarea name="mytextarea" rows="3" cols="15">Text in the text area</textarea>
And even more, more text.
</p>
创建一个单独的段落块,其文本位于
Is the CSS 'width'
property applicable to a <textarea>
?
In practice, people say that they use it successfully, for example using a rule like this:
textarea
{
width:100%;
}
What's confusing me is that the CSS 2.1 specification for width says,
This property specifies the content
width of boxes generated by
block-level and replaced elements.
This property does not apply to
non-replaced inline-level elements.
I thought that a textarea is an inline-level element, because e.g. markup like this ...
<p>
This is some more text:
<textarea name="mytextarea" rows="3" cols="15">Text in the text area</textarea>
And even more, more text.
</p>
... creates a single paragraph block with text to the left and right of the <textarea>
, and that therefore according to the spec the width shouldn't be applicable.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Textarea 是一个内联级别元素...一个替换内联元素(您得到一个表单控件,而不是元素的简单内容)。
该规范排除了不可替换的内联元素,但 textarea 不是其中之一。
Textarea is an inline level element… a replaced inline element (you get a form control, not the simple content of the element).
The spec excludes non-replaced inline elements, but textarea is not one of them.
宽度不是 textarea 元素可接受的属性。文本区域的大小可以通过 cols 和 rows 属性指定,尽管可以通过 CSS height 和 width 属性更好地控制它。
Width is not an acceptable attribute of the textarea element. The size of a textarea can be specified by the cols and rows attributes, although it can be better controlled through the CSS height and width properties.
您应该使用“cols”属性来设置文本区域的宽度。
http://www.w3schools.com/TAGS/tag_textarea.asp
you should use the 'cols' property to set the width of the textarea.
http://www.w3schools.com/TAGS/tag_textarea.asp