DropdownMenu changes padding / margin on document body.
See original GitHub issueBug report
Current Behavior
When active, the DropdownMenu component adds the following CSS to the document body.
body {
overflow: hidden !important;
position: relative !important;
padding-left: 8px;
padding-top: 8px;
padding-right: 8px;
margin-left:0;
margin-top:0;
margin-right: 0px !important;
}
This can cause layout shift on layouts that have set padding / margin on the body.
Expected behavior
Opening the dropdown should not cause the layout to shift.
Reproducible example
Suggested solution
I’m guessing that the margins / padding have a function, though it isn’t clear to me what that is. As long as that part of the CSS may be removed without breaking the component, I would suggest removing the padding / margins.
Your environment
Software | Name(s) | Version |
---|---|---|
Radix Package(s) | Dropdown | 0.0.1 |
React | n/a | 17.0.0 |
Browser | Chrome | |
Assistive tech | n/a | |
Node | n/a | |
npm/yarn | ||
Operating System | Mac |
Issue Analytics
- State:
- Created 3 years ago
- Comments:16 (3 by maintainers)
Top Results From Across the Web
Dropdown menu moves content - Stack Overflow
In your css add this styles to the current ones. .element { position: relative; } .menu>ul>li>ul { position: absolute; background-color: #555; width: 100%; ......
Read more >Simple CSS drop down menu issues - SitePoint
The css technique for showing a drop down requires the drop down to be enclosed in the element that is being hovered while...
Read more >How To Adjust the Content, Padding, Border, and Margins of ...
Adjusting the Margin Size of an HTML Element With CSS You can remove this margin by setting the top and left margin to...
Read more >How To Create a HTML Dropdown Menu - YouTube
How To Create a HTML Dropdown Menu | CSS Dropdown Tutorial Today we are going ... It is not necessary to use javascript,...
Read more >Dropdowns · Bootstrap v5.0
We use this extra class to reduce the horizontal padding on either side of the caret by 25% and remove the margin-left that's...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@benoitgrelard Sorry, it was a typo and badly explained. What I meant was even if you set
display: flow-root;
, the problem still persists due to this styleposition: relative !important;
being applied by the library on the body. The solution that worked for me (using Tailwind):@benoitgrelard that doesn’t solve @steveruizok’s recent example unfortunately. the snippet i posted should work for all cases i believe.