This is a migrated thread and some comments may be shown as answers.

popups offset incorrect when body margin set to auto

5 Answers 353 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Orrin
Top achievements
Rank 1
Orrin asked on 07 Feb 2014, 06:33 PM
On my page I have my body element centered in the browser window with body { margin: 0 auto; }.  When I trigger any popup, such as an autocomplete list or kendo window, the popup wrapper is positioned too far to the right.  

For example, if the body's left offset is 400px, then that's how far off to the right the popup window is misplaced.  If I shrink my browser window so it just fits the body (making the body margin effectively 0) then the popup is positioned correctly.

So, it appears that having an auto margin on a parent element is not being handled properly when calculating the position of the popup container.

5 Answers, 1 is accepted

Sort by
0
Kiril Nikolov
Telerik team
answered on 11 Feb 2014, 08:04 AM
Hi Orrin,

I am not sure that I understand exactly your setup. You set margin: 0 auto to the body, and then you said that you have left offset of 400px, how do you set this offset? Isn't it set to auto already?

Please edit this example, so it can show the issue:

http://jsbin.com/duday/2/edit

Regards,
Kiril Nikolov
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Orrin
Top achievements
Rank 1
answered on 12 Feb 2014, 05:46 PM
I meant to say the left/right margin of 400px is the result of setting the side margins to auto (which is of course tied to how wide the
window is).

I updated the jsbin sample and only needed to modify one detail.  The css postion on body is now set to relative.

http://jsbin.com/vapiw/1/edit?html,css,output
0
Kiril Nikolov
Telerik team
answered on 13 Feb 2014, 11:26 AM
Hi Orrin,

Setting position relative to the body element is not supported with Kendo UI. All the popups that we use are aligned to the body, so the behavior that you see is expected. If you want to center the body, you can just another elements that you can apply your styling to.

Regards,
Kiril Nikolov
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Jim
Top achievements
Rank 1
Veteran
answered on 01 Apr 2021, 01:47 PM

I know this is a very old post.  But, I ran in to this issue today.  Setting margin:auto on the Body does indeed offset the dropdown box list.

I fixed this by setting the Body position:relative.

I am using Telerik Blazor UI 2.20, and .NET 5 Core Hosted WebAssembly project.

0
Nadezhda Tacheva
Telerik team
answered on 05 Apr 2021, 10:15 AM

Hi Orrin,

Indeed, setting margin:auto to the body affects the DropDownList popup position (and other dropdown components such as Autocomplete, Multiselect) -  see the second bullet under common cases for Wrong Popup position in this article.

The reason behind this behavior is that with such a setup the  <TelerikRootComponent> will not match the <body> and the browser viewport and popup offset is the expected outcome.

In order not to experience such a mismatch in the position of the popup, you can also remove the default margin of the body element ( set margin:0 ) and apply the desired layout on an inner element (such as a <div> inside the app or body).

Regards,
Nadezhda Tacheva
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
General Discussions
Asked by
Orrin
Top achievements
Rank 1
Answers by
Kiril Nikolov
Telerik team
Orrin
Top achievements
Rank 1
Jim
Top achievements
Rank 1
Veteran
Nadezhda Tacheva
Telerik team
Share this question
or