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

Joh*_*ohn 2 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>
Run Code Online (Sandbox Code Playgroud)

的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;
}
Run Code Online (Sandbox Code Playgroud)

这是一个Stackblitz

编辑 当前结果:

当前结果

期望的结果:(对不起我的图像编辑能力很差) 所需结果

Bru*_*ack 5

您可以使用以下代码实现此目的:

隐藏:

button {
  overflow-x: hidden !important;
}
Run Code Online (Sandbox Code Playgroud)

断词:

button{
  white-space: pre-wrap !important;
}
Run Code Online (Sandbox Code Playgroud)

  • 大。谢谢。正是我需要的^^我也可以使用`button`-选择器来确认它有效,并且您不需要`!important`-flag;) (2认同)