|
| 1 | +--- |
| 2 | +title: Center Telerik Window Horizontally and Keep Fixed Top Position |
| 3 | +description: Learn how to center a Telerik Window only horizontally while keeping it at a fixed distance from the top in Blazor applications. |
| 4 | +type: how-to |
| 5 | +page_title: How to Center Telerik Window Horizontally with a Fixed Top Position in Blazor |
| 6 | +slug: window-kb-center-horizontally-fixed-top |
| 7 | +tags: window, center horizontally, positioning, blazor, fixed top |
| 8 | +res_type: kb |
| 9 | +ticketid: 1672113 |
| 10 | +--- |
| 11 | + |
| 12 | +## Environment |
| 13 | +<table> |
| 14 | + <tbody> |
| 15 | + <tr> |
| 16 | + <td>Product</td> |
| 17 | + <td>Window for Blazor</td> |
| 18 | + </tr> |
| 19 | + </tbody> |
| 20 | +</table> |
| 21 | + |
| 22 | +## Description |
| 23 | + |
| 24 | +I want to center a Telerik Window horizontally in my Blazor application but keep it at a fixed distance from the top without using JavaScript for calculations. |
| 25 | + |
| 26 | +This knowledge base article answers the following questions: |
| 27 | +- How can I center a Telerik Window only horizontally in Blazor? |
| 28 | +- Is it possible to position a Telerik Window at a fixed distance from the top in Blazor while centering it horizontally? |
| 29 | + |
| 30 | +## Solution |
| 31 | + |
| 32 | +To center a Telerik Window horizontally while maintaining a fixed distance from the top, follow these steps: |
| 33 | +1. Apply a [custom CSS class]({%slug themes-override%}) to the Window. |
| 34 | +1. Use this CSS class to set the initial top value, manage the horizontal centering and override the default vertical transformation. |
| 35 | + |
| 36 | +>caption Telerik Blazor Window Centered Horizontally with Fixed Top Value |
| 37 | +
|
| 38 | +````CSHTML |
| 39 | +<TelerikButton OnClick="@( () => WindowVisible = !WindowVisible )">Toggle Window</TelerikButton> |
| 40 | +
|
| 41 | +<style> |
| 42 | + .k-centered.centered-top { |
| 43 | + top: 100px; |
| 44 | + transform: translate(-50%, -0); |
| 45 | + } |
| 46 | +</style> |
| 47 | +
|
| 48 | +<TelerikWindow @bind-Visible="@WindowVisible" |
| 49 | + Class="centered-top" > |
| 50 | + <WindowActions> |
| 51 | + <WindowAction Name="Minimize" /> |
| 52 | + <WindowAction Name="Close" /> |
| 53 | + </WindowActions> |
| 54 | + <WindowTitle> |
| 55 | + Window Title |
| 56 | + </WindowTitle> |
| 57 | + <WindowContent> |
| 58 | + Window Content |
| 59 | + </WindowContent> |
| 60 | +</TelerikWindow> |
| 61 | +
|
| 62 | +@code { |
| 63 | + private bool WindowVisible { get; set; } = true; |
| 64 | +} |
| 65 | +```` |
| 66 | + |
| 67 | +## See Also |
| 68 | +- [Telerik Window for Blazor - Overview]({%slug window-overview%}) |
0 commit comments