如果“角度材质”按钮中的文本长于按钮的宽度,该如何打断单词?

时间:2018-11-27 10:03:17

标签: css angular-material2

如何通过将文本包装在按钮内来确保Angular Material Button内的文本不会溢出。我尝试了以下方法:

HTML

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

CSS

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

这里是Stackblitz

编辑 当前结果:

Current result

所需结果:(很抱歉,我的图像编辑能力很差) Desired result

1 个答案:

答案 0 :(得分:3)

您可以使用以下代码来实现:

隐藏:

button {
  overflow-x: hidden !important;
}

分词:

button{
  white-space: pre-wrap !important;
}