Set font size of Angular Material Tooltip

2020-02-11 17:22发布

I am very new to web development, and I cannot figure out how to solve the following issue, although it may be very easy.

I am using Angular 4 and Angular Material to implement tooltips like this:

<div mdTooltip="tooltip text" mdTooltipPosition="above">
  <span>Show tooltip</span>
</div>

I would like to make the font size of the tooltip text bigger. However, I did not manage to find how to do this in the Angular Material documentation, neither searching in the web. Does anyone have any idea on how to do this? Thanks.

7条回答
女痞
2楼-- · 2020-02-11 18:14

Per the documentation here: https://material.angular.io/components/tooltip/api

And the spec: https://github.com/angular/material2/blob/master/src/lib/tooltip/tooltip.spec.ts

You can set the property 'matTooltipClass', as follows:

<div matTooltip="tooltip text" matTooltipPosition="above" matTooltipClass="tooltip">
  <span>Show tooltip</span>
</div>

Then in your CSS (global - not for the component):

  .mat-tooltip.tooltip {
    background-color: darkblue;
    font-size: 12px;
  }

Also see their demo here: https://github.com/angular/material2/tree/master/src/demo-app/tooltip

Also keep in mind if you are using SASS, that the container for the tooltip is at the bottom and nowhere near where you are placing it in your component's HTML, so do not nest it in that component. Make sure it is standalone, otherwise it will not work. This note applies as well obviously to the comment above if you just choose to override .mat-tooltip

To see the changes, in developer tools, find the div at the bottom with the class "cdk-overlay-container". Then hover over the element. You can use your arrow keys to navigate into the element while you are hovered over to confirm whether your class is being added.

查看更多
登录 后发表回答