Skip to content

Commit 53cc491

Browse files
kendo-botKB BotTsvetomir-Hr
authored andcommitted
Added new kb article tooltip-position-rotated-div (#2526)
* Added new kb article tooltip-position-rotated-div * chore(kb): update slug and examples * chore: apply recommendations --------- Co-authored-by: KB Bot <[email protected]> Co-authored-by: Tsvetomir Hristov <[email protected]>
1 parent f89c144 commit 53cc491

File tree

1 file changed

+138
-0
lines changed

1 file changed

+138
-0
lines changed
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
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 tooltip-overview%}) 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+
### Use an Inner Tooltip Target
40+
41+
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.
42+
43+
````RAZOR
44+
<TelerikTooltip TargetSelector=".tooltip-target .inner-target" Class="dynamic-tooltip-styles" />
45+
46+
<div style="padding: 5em;">
47+
Hover this rectangle ...
48+
49+
<span class="tooltip-target" style="transform: rotate(-20deg);">
50+
<span title="More info..." class="inner-target">
51+
<TelerikSvgIcon Icon="@SvgIcon.InfoCircle" Size="@ThemeConstants.SvgIcon.Size.ExtraLarge" />
52+
</span>
53+
</span>
54+
55+
... or this one ...
56+
57+
<span class="tooltip-target" style="transform: rotate(45deg);">
58+
<span title="More info..." class="inner-target">
59+
<TelerikSvgIcon Icon="@SvgIcon.InfoCircle" Size="@ThemeConstants.SvgIcon.Size.ExtraLarge"/>
60+
</span>
61+
</span>
62+
</div>
63+
64+
<style>
65+
.tooltip-target {
66+
display: inline-block;
67+
width: 120px;
68+
height: 25px;
69+
background: yellow;
70+
position: relative;
71+
}
72+
73+
.tooltip-target .inner-target {
74+
position: absolute;
75+
right: .4em;
76+
bottom: 0;
77+
}
78+
</style>
79+
````
80+
81+
### Adjust Tooltip Margin Dynamically
82+
83+
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.
84+
85+
````RAZOR
86+
<TelerikTooltip TargetSelector=".tooltip-target" Class="dynamic-tooltip-styles" />
87+
88+
<div style="padding: 5em;">
89+
Hover this rectangle ...
90+
91+
<span class="tooltip-target" title="Foo Tooltip" style="transform: rotate(-10deg);"
92+
@onmouseover="@( (MouseEventArgs args) => OnTooltipTargetOver("15px") )">
93+
</span>
94+
95+
<br /> <br /> <br /> <br /> <br />
96+
<br /> <br /> <br /> <br /> <br />
97+
98+
... or this one ...
99+
100+
<span class="tooltip-target" title="Bar Tooltip" style="transform: rotate(45deg);"
101+
@onmouseover="@( (MouseEventArgs args) => OnTooltipTargetOver("60px") )">
102+
</span>
103+
</div>
104+
105+
<style>
106+
.tooltip-target {
107+
display: inline-block;
108+
width: 200px;
109+
height: 20px;
110+
background: yellow;
111+
}
112+
113+
/* Remove tooltip callout */
114+
.dynamic-tooltip-styles .k-callout {
115+
display: none;
116+
}
117+
118+
/* Move tooltip, depending on target CSS transform */
119+
.dynamic-tooltip-styles {
120+
margin-top: @TooltipMarginTop;
121+
}
122+
</style>
123+
124+
@code {
125+
private string TooltipMarginTop { get; set; } = string.Empty;
126+
127+
private void OnTooltipTargetOver(string marginTop)
128+
{
129+
TooltipMarginTop = marginTop;
130+
}
131+
}
132+
````
133+
134+
## See Also
135+
136+
- [Telerik Blazor Tooltip - Overview]({%slug tooltip-overview%})
137+
- [Hide the Tooltip Callout or Change Its Position]({%slug tooltip-kb-callout-position%})
138+
- [Custom ToolTip Styles and Colors]({%slug tooltip-kb-custom-styles%})

0 commit comments

Comments
 (0)