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
Is it possible to use text-overflow: ellipsis on a button element?
提问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 span
element 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/
回答by Andreyco
Yeah, it is. Your example is working perfectly! :)
是啊,就是。你的例子工作得很好!:)