根据实际定位将 CSS 三角形附加到 MatTooltip?

Attach CSS triangle to MatTooltip depending on actual positioning?

我一直在绞尽脑汁想办法将一个小 CSS 三角形附加到 Angular 中的 MatTooltip 上,该三角形从 [=12= 处切换] 当工具提示显示在宿主元素下方(默认)到 bottom 当工具提示位于宿主元素上方时(例如,当宿主元素太靠近视口底部时)。

Am I missing some property that would give me a way to switch the CSS class? Or is it simply impossible?

非常感谢任何帮助。

欢迎来到 SO!

虽然你可以用css画尖三角形到mat-tooltip但是你不能根据View-port/DOM视图像上面或下面那样移动它的位置,所以它不能移动尖三角形。

解法:

I have used SAT Popover for styling tooltips. You can give it an angular component and it will display as you style it.

https://ncstate-sat.github.io/popover/

有可能。

由于 MatTooltip 通过 transform-origin 控制其定位,您可以使用它。

例如,.mat-tooltip[style*="transform-origin: left center"]仅选择显示在其父项右侧的工具提示,因此您可以在工具提示的左侧显示三角形。

transform-origin的值:

  • 父项右侧的工具提示:left center
  • 父项左侧的工具提示:right center
  • 父项上方的工具提示:center top
  • 其父项下方的工具提示:center bottom