Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Button overflow hidden not working

Tags:

html

css

I have the following:

enter image description here

Fiddle link

html:

<button>Here's a long chunk of text</button>

css:

button {
   width: 80px;
   overflow: hidden;
}

Basically, I want the button not to wrap the text..

I'm sure I'm just missing something obvious, but I can't figure it out...

like image 384
Rob Avatar asked Nov 29 '22 11:11

Rob


2 Answers

Add the following style to prevent line breaks:

{
    white-space: nowrap;
}

Updated Fiddle

EDIT

Now, since you're trying to hide the overflow, I'd suggest to use text-overflow: ellipsis; to give better looks to the text cut, adding a (...) at the end:

Another Updated Fiddle

button {
    width: 80px;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}
<button>Here's a long chunk of text</button>
like image 179
LcSalazar Avatar answered Dec 18 '22 18:12

LcSalazar


You can use white-space: nowrap;:

button {
    width: 80px;
    overflow: hidden;
    white-space: nowrap;
}
<button>Here's a long chunk of text</button>
like image 40
Alex Char Avatar answered Dec 18 '22 20:12

Alex Char