Reputation: 2110
I have the following:
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...
Upvotes: 4
Views: 15592
Reputation: 16821
Add the following style to prevent line breaks:
{
white-space: nowrap;
}
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:
button {
width: 80px;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}
<button>Here's a long chunk of text</button>
Upvotes: 12
Reputation: 4370
add white-space: nowrap;
and word-wrap: normal;
word-wrap:
The word-wrap property allows long words to be able to be broken and wrap onto the next line.
white-space:
The white-space property specifies how white-space inside an element is handled.
button {
width: 80px;
overflow: hidden;
white-space: nowrap;
word-wrap: normal;
}
<button>Here's a long chunk of text</button>
Upvotes: 2
Reputation: 207891
Add white-space:nowrap;
button {
width: 80px;
overflow: hidden;
white-space:nowrap;
}
Upvotes: 2
Reputation: 33218
You can use white-space: nowrap;
:
button {
width: 80px;
overflow: hidden;
white-space: nowrap;
}
<button>Here's a long chunk of text</button>
Upvotes: 5