https://plnkr.co/edit/dZigMtncPEed4MK75swb?p=preview
<button style="width: 50px" type = "submit">Very very very verey looooooooooooooooooooooong</button>
As you can see, the text extends outside. Is there any way to truncate the text? The reason behind this is it is that the button is part of a drop down menu.
The text is white so it might hard to see it 'breaking' the button.
[UPDATE]
Is there anyway to add margin to the text-overflow: ellipsis. The ellipsis is too close to the text and it is not appealing (in my opinion)
[UPDATE 2] Since I usually put my caret at the end of the text, the solution above cause my caret to be missing. Is there any way for me to put an ellipses follow a caret?
[UPDATE 3] Is there anyway to make the caret align at the very end?
Remove the width and display: block and then add display: inline-block to the button. To have it remain centered you can either add text-align: center; on the body or do the same on a newly created container.
give the xp-t-bold class padding. That will increase the width of the parent span as well. . xp-t-bold { padding:20px; // overall width will be increased by 40px. }
The word-wrap property is used to split/break long words and wrap them into the next line. word-break: break-all; It is used to break the words at any character to prevent overflow. word-wrap: break-word; It is used to broken the words at arbitrary points to prevent overflow.
The easiest way to have a line break is using the <br> tag on your text. It is used for inserting a single line break.
If you want to truncate the text and add ellipsis, you could add overflow: hidden
to clip the text, and then use text-overflow: ellipsis
to add the '... ' ellipsis:
Updated Example
button.truncate {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With