CSS 是否可以在按钮元素上使用文本溢出:省略号?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9905409/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 03:25:54  来源:igfitidea点击:

Is it possible to use text-overflow: ellipsis on a button element?

css

提问by wilsonpage

I am not sure whether it is possible to use the text-overflow: ellipsis;style on a <button>element. Here is my attempt: http://jsfiddle.net/WilsonPage/tK727/

我不确定是否可以text-overflow: ellipsis;<button>元素上使用样式。这是我的尝试:http: //jsfiddle.net/WilsonPage/tK727/

回答by Jukka K. Korpela

Due to limitations in browsers, wrap the button text inside e.g. a spanelement and set the styles on it. Example (available as jsfiddletoo):

由于浏览器的限制,将按钮文本包裹在例如一个span元素中并在其上设置样式。示例(也可用作jsfiddle):

<style>
.buttontext {
  width: 95px;
  overflow: hidden;
  white-space: nowrap;
  display: block;
  text-overflow: ellipsis;
}?
</style>
<button><span class="buttontext">Very long text Very long text
Very long text</span></button>

回答by Shailender Arora

ya its possible & i have tested on major browsers as well as its working

是的,我已经在主要浏览器上进行了测试以及它的工作

you can see the live demo:-http://jsfiddle.net/tK727/2/

你可以看到现场演示:- http://jsfiddle.net/tK727/2/

you can read more about text-overflow property

您可以阅读有关文本溢出属性的更多信息

回答by Andreyco

Yeah, it is. Your example is working perfectly! :)

是啊,就是。你的例子工作得很好!:)