How do I make sure that the text inside an Angular Material Button does not overflow, by wrapping the text inside the button. I have tried the following:
<div class="cotnainer">
<button mat-raised-button color="accent">Click me! This is a long text, but I want to to wrap if content is overflowing
</button>
</div>
.container{
width: 200px;
height:200px;
background-color: silver;
}
button{
max-width: 100%;
}
span, .mat-button-wrapper{ // I have tried all of the following options, but it does not work.
max-width: 100% !important;
word-break: break-all !important;
overflow: hidden !important;
}
Here is a Stackblitz
EDIT Current result:
Desired result: (sorry for my poor image editing skills)
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.
Use word-wrap:break-word; It even works in IE6, which is a pleasant surprise. word-wrap: break-word has been replaced with overflow-wrap: break-word; which works in every modern browser.
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.
You can achieve this with this code:
Hiding:
button {
overflow-x: hidden !important;
}
Word Break:
button{
white-space: pre-wrap !important;
}
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