向 MatTooltip 添加箭头

问题描述 投票:0回答:1

我想在 Angular 16 上使用 MatTooltip 添加一个箭头。但是由于某种原因,使用箭头的伪元素覆盖材质并不像许多帖子中建议的那样工作。 这是我的代码:

<th class="value-style" matTooltip={{tile.tooltip}} [matTooltipPosition]='tooltipPosition' matTooltipClass="TooltipClass">{{tile.count}}</th>

在SCSS中

.homeTooltipClass {
  .mdc-tooltip__surface {
    background: rgba($color:black, $alpha: 1) !important;
    background-color: black;
    color: white !important;
    font-size: 14px !important;
    max-width: 200px !important;
    border: 1px solid black;
    padding: 5px;
    box-shadow: 1px 1px black;    
  }
}
 public tooltipPosition: TooltipPosition = "above";
angular angular-material tooltip
1个回答
0
投票

我真的无法想象你如何画“箭头”,但你需要考虑三件事

  1. .css 应该是“全局”样式(例如,在 styles.css 中) 你的申请。材质角度在 cdk 面板中创建工具提示 应用程序“外部”。

  2. 您应该指示溢出:工具提示可见

    .mat-tooltip.TooltipClass{
      overflow: visible;
    }
    
  3. 绘制底部箭头的示例

    .mat-tooltip.TooltipClass::after {
      content: " ";
      position: absolute;
      top: 100%; /* At the bottom of the tooltip */
      left: 50%;
      margin-left: -5px;
      border-width: 5px;
      border-style: solid;
      border-color: rgba(97, 97, 97, .9) transparent transparent transparent;
    }
    

A stackblitz

注意:在材料 v16 中,班级应该是

mat-mdc-tooltip

© www.soinside.com 2019 - 2024. All rights reserved.