Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

css

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/

like image 758
wilsonpage Avatar asked Mar 28 '12 10:03

wilsonpage


People also ask

Can I use text-overflow ellipsis?

The text-overflow CSS property sets how hidden overflow content is signaled to users. It can be clipped, display an ellipsis (' … '), or display a custom string.

How do I force text-overflow ellipsis?

To force overflow to occur and ellipses to be applied, the author must apply the nowrap value to the white-space property on the element, or wrap the content in a <NOBR> tag.

How do I use text-overflow ellipsis in a div?

The overflowing content can be clipped, display an ellipsis ('…'), or display a custom string. Syntax: text-overflow: clip|string|ellipsis|initial|inherit; Property Values: All the properties are described well with the example below.

How does text-overflow ellipsis work?

The text-overflow property in CSS deals with situations where text is clipped when it overflows the element's box. It can be clipped (i.e. cut off, hidden), display an ellipsis ('…', Unicode Range Value U+2026) or display an author-defined string (no current browser support for author-defined strings).


1 Answers

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

<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> 
like image 141
Jukka K. Korpela Avatar answered Sep 21 '22 21:09

Jukka K. Korpela