Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Text extends outside button HTML

Tags:

html

css

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.

enter image description here

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)

enter image description here

[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?

enter image description here

[UPDATE 3] Is there anyway to make the caret align at the very end? enter image description here

like image 800
Zanko Avatar asked Jan 03 '16 20:01

Zanko


People also ask

How do I make text fit a button in CSS?

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.

How do you extend a button in HTML?

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. }

How do you wrap text next line in HTML?

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.

How do I add a new button to the next line?

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.


1 Answers

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;
}

enter image description here

like image 83
Josh Crozier Avatar answered Oct 12 '22 13:10

Josh Crozier