Html 在 IE 的多行文本框中隐藏垂直滚动条
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1409979/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Hiding vertical scrollbar in multi-line textbox in IE
提问by dani
I have a multiline textbox :
我有一个多行文本框:
<asp:TextBox ID="txtBody" runat="server" TextMode="MultiLine" Rows="10" Width="95%" />
In ie there is a vertical scrollbar bar even if a text inside textbox doesn't occupy 10 lines.
In firefox it does not happen, scroll bar appears only if text exceeds 10 lines.
在 ie 中有一个垂直滚动条,即使文本框内的文本不占用 10 行。
在 Firefox 中不会发生这种情况,仅当文本超过 10 行时才会出现滚动条。
What can be done?
可以做什么?
回答by awe
Set CSS style overflow to auto:
将 CSS 样式溢出设置为自动:
<asp:TextBox ID="txtBody" runat="server" TextMode="MultiLine"
Rows="10" Width="95%" style="overflow:auto;" />
The default behavior differs between browsers, which is why you see different behavior in IE and FF when overflow
is not specified.
默认行为因浏览器而异,这就是为什么您在overflow
未指定时在 IE 和 FF 中看到不同行为的原因。
To override default browser behaviour for all multiline textboxes on your page, you can add it in a style definition. Then you don't need to include the inline style on each textbox:
要覆盖页面上所有多行文本框的默认浏览器行为,您可以将其添加到样式定义中。然后你不需要在每个文本框上包含内联样式:
Note:Multiline TextBox is rendered using HTML tag <textarea>
, so we will specify the css style for the textarea
element type.
注意:多行文本框使用 HTML 标签呈现<textarea>
,因此我们将为textarea
元素类型指定 css 样式。
textarea {
overflow: auto;
}
<textarea id="txtBody1" rows="5">Text in
textbox
with
many
lines,
so that
scrollbar
will
appear.
</textarea>
<textarea id="txtBody2" rows="5">Smaller text, no scrollbar.</textarea>
回答by rahul
It is the default behavior of IE. The default value of overflow is visible and IE adds a disabled scroll bar even if the content does not overflow.
这是 IE 的默认行为。溢出的默认值是可见的,即使内容没有溢出,IE 也会添加禁用的滚动条。
You can add a css class to the element
您可以向元素添加一个 css 类
<style>
.Over { overflow: auto; width: 95%; }
</style>
<asp:TextBox ID="txtBody" runat="server" CssClass="Over" TextMode="MultiLine" Rows="10" />