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 17:50

You can use css /deep/ selector. For example:

/deep/ .mat-tooltip {
  font-size: 14px;
}

Then you do not have to use !important

查看更多
女痞
3楼-- · 2020-02-11 17:53

Add ng-deep before class name

Try this

::ng-deep .mat-tooltip {
    background: red!important;
}
查看更多
【Aperson】
4楼-- · 2020-02-11 18:00

Try this way. It should work.

test.component.html

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

test.component.ts

@Component({
  selector: 'test',
  templateUrl: './test.component.html',
  styleUrls: ['./test.component.scss'],
  encapsulation: ViewEncapsulation.None,
  /*
  styles: [`
   .myTest-tooltip {
      min-width: 300px;
      background-color: #FC5558;
      font-size: 16px;
   }
`]*/
})

test.component.scss

.myTest-tooltip {
    min-width: 300px;
    background-color: #FC5558;
    font-size: 16px;
}
查看更多
放我归山
5楼-- · 2020-02-11 18:03

add following code in your styles.css to increase its font size i.e. 12px

CSS

.mat-tooltip {
  font-size: 14px !important;
}

and use matTooltip in your tag's as.

<p matTooltip="My Tooltip">...<p>
查看更多
6楼-- · 2020-02-11 18:08

You can fix this by adding a .mat-tooltip css declaration in you main styles file and change the font size there. You need to set !important on the font size otherwise it won't show up.

查看更多
神经病院院长
7楼-- · 2020-02-11 18:12

I dont have an experience with angular but you may add a class or id for div. Then you may control with this class or id with css file.

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

And

.sth{
    font-size:20px;
}

in css file.

查看更多
登录 后发表回答