Skip to content

Commit 5c2811e

Browse files
author
KB Bot
committed
Added new kb article tooltip-position-rotated-div
1 parent 0cc9c7e commit 5c2811e

File tree

1 file changed

+137
-0
lines changed

1 file changed

+137
-0
lines changed
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
---
2+
title: Adjusting Tooltip Position for Rotated Divs in Blazor
3+
description: Learn how to adjust the position of the Telerik Blazor Tooltip when the target element is rotated, ensuring it displays correctly.
4+
type: how-to
5+
page_title: How to Correct Tooltip Position on Rotated Elements in Blazor
6+
slug: tooltip-kb-position-rotated-div
7+
tags: tooltip, blazor, css
8+
res_type: kb
9+
ticketid: 1657431
10+
---
11+
12+
## Environment
13+
14+
<table>
15+
<tbody>
16+
<tr>
17+
<td>Product</td>
18+
<td>
19+
Grid for Blazor, <br />
20+
Tooltip for Blazor
21+
</td>
22+
</tr>
23+
</tbody>
24+
</table>
25+
26+
## Description
27+
28+
When rotating div elements that have an associated [Tooltip]({%slug %}) to display additional information, the Tooltip might not align correctly with the target element. The goal is to adjust the Tooltip's position so it aligns appropriately with the center of the rotated div, and optionally, remove the Tooltip's callout pointer for a cleaner appearance.
29+
30+
This KB article also answers the following questions:
31+
- How to correctly position a Tooltip on a rotated div in Blazor?
32+
- How can I hide the callout pointer of a Tooltip in Blazor?
33+
- Is there a way to dynamically adjust Tooltip positioning based on element rotation in Blazor?
34+
35+
## Solution
36+
37+
To address the issue of Tooltip misalignment on rotated div elements, consider the following two approaches:
38+
39+
### Adjust Tooltip Margin Dynamically
40+
41+
Calculate the necessary offset for the Tooltip and apply it as a margin style. Additionally, this solution includes how to hide the Tooltip's callout.
42+
43+
````RAZOR
44+
<TelerikTooltip TargetSelector=".tooltip-target" Class="dynamic-tooltip-styles" />
45+
46+
<div style="padding: 5em;">
47+
Hover this rectangle ...
48+
49+
<span class="tooltip-target" title="Foo Tooltip" style="transform: rotate(-10deg);"
50+
@onmouseover="@( (MouseEventArgs args) => OnTooltipTargetOver("15px") )">
51+
FOO
52+
</span>
53+
54+
... or this one ...
55+
56+
<span class="tooltip-target" title="Bar Tooltip" style="transform: rotate(45deg);"
57+
@onmouseover="@( (MouseEventArgs args) => OnTooltipTargetOver("60px") )">
58+
BAR
59+
</span>
60+
</div>
61+
62+
<style>
63+
.tooltip-target {
64+
display: inline-block;
65+
width: 200px;
66+
height: 20px;
67+
background: yellow;
68+
}
69+
70+
/* Remove tooltip callout */
71+
.dynamic-tooltip-styles .k-callout {
72+
display: none;
73+
}
74+
75+
/* Move tooltip, depending on target CSS transform */
76+
.dynamic-tooltip-styles {
77+
margin-top: @TooltipMarginTop;
78+
}
79+
</style>
80+
81+
@code {
82+
private string TooltipMarginTop { get; set; } = string.Empty;
83+
84+
private void OnTooltipTargetOver(string marginTop)
85+
{
86+
TooltipMarginTop = marginTop;
87+
}
88+
}
89+
````
90+
91+
### Use an Inner Tooltip Target
92+
93+
Embed a tooltip target within the rotated element that won't be affected by the rotation. This method ensures the Tooltip aligns correctly without additional adjustments.
94+
95+
````RAZOR
96+
<TelerikTooltip TargetSelector=".tooltip-target .inner-target" Class="dynamic-tooltip-styles" />
97+
98+
<div style="padding: 5em;">
99+
Hover this rectangle ...
100+
101+
<span class="tooltip-target" style="transform: rotate(-20deg);">
102+
FOO
103+
<span title="Foo Tooltip" class="inner-target">
104+
<TelerikSvgIcon Icon="@SvgIcon.QuestionCircle" />
105+
</span>
106+
</span>
107+
108+
... or this one ...
109+
110+
<span class="tooltip-target" style="transform: rotate(45deg);">
111+
BAR
112+
<span title="Bar Tooltip" class="inner-target">
113+
<TelerikSvgIcon Icon="@SvgIcon.QuestionCircle" />
114+
</span>
115+
</span>
116+
</div>
117+
118+
<style>
119+
.tooltip-target {
120+
display: inline-block;
121+
width: 120px;
122+
height: 20px;
123+
background: yellow;
124+
position: relative;
125+
}
126+
127+
.tooltip-target .inner-target {
128+
position: absolute;
129+
right: .4em;
130+
bottom: 0;
131+
}
132+
</style>
133+
````
134+
135+
## See Also
136+
137+
- [Telerik Blazor Tooltip - Overview]({%slug tooltip-overview%})

0 commit comments

Comments
 (0)