Skip to content

fix(theme): clip overflowed navbar menu - #5364

Open
bluwy wants to merge 2 commits into
mainfrom
clip-nav-bar-menu
Open

fix(theme): clip overflowed navbar menu#5364
bluwy wants to merge 2 commits into
mainfrom
clip-nav-bar-menu

Conversation

@bluwy

@bluwy bluwy commented Aug 12, 2026

Copy link
Copy Markdown
Collaborator

Description

In the navbar, make the navbar menu flex-grow: 1 (instead of the search bar) and clip it if there's no more space left, e.g. the screen isn't wide enough. Now, the navbar shouldn't ever exceed the screen width and cause the scrolling in the first place

I'll make some comments below explaining some of the changes.

Here's also a video of the new behaviour:

vitepress-navbar.mp4

Linked Issues

fix #2842

Additional Context

In the linked issue, the scrolling happened in the first place on smaller screens is because the navbar became position: relative, while in larger screens it was position: fixed. I decided to fix this differently by making the navbar menu properly clipped in both cases instead.


Tip

The author can publish a preview release by commenting /publish after creating the PR.

@bluwy
bluwy marked this pull request as draft August 12, 2026 09:39
@bluwy
bluwy marked this pull request as ready for review August 12, 2026 09:48
.button[aria-expanded="false"] + .menu {
opacity: 0;
visibility: hidden;
transform: translateY(0);

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was removed because of a Safari bug that causes the menu to get wrongly clipped. It was also reported in #5050 before.

I noticed an easy fix here is to not use transform here (as it's also not doing anything). This could break for users that set translateY(-2px) or something to have a cool floating effect, but I think it's fine? Alternative I also found that setting will-change: transform fixes it, but this technically incurs some small perf overhead for everyone.


.content {
flex-grow: 1;
min-width: 0;

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This min-width: 0 (on the flex item parent) allows shrinking the content beyond its content, same for the min-width: 0 in VPNavBarMenu. Both is needed to work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

When browser width is between 840px and 770px a horizontal scrollbar appears when there are too many items

1 participant