Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: wiggling nav items #123

Merged
merged 1 commit into from
Apr 19, 2024

Conversation

huyenltnguyen
Copy link
Member

Checklist:

This PR changes the box model from content-box to border-box to prevent the nav items from wiggling on hover.

Screenshots (containing animated images)
Before After
nav-items-before nav-items-after

&:active,
&:hover,
&:focus {
background-color: $--gray75 $i;
Copy link
Member Author

Choose a reason for hiding this comment

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

Without the !important flag, this rule has no effect.

border: 0px;
}
box-sizing: border-box;
border: 0px $i;
Copy link
Member Author

Choose a reason for hiding this comment

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

Took me longer than I wanted to figure this out.

The issue is:

  • The element has box-sizing being content-box, meaning its width and height don't account for padding or border.
  • We do have height being 34px (instead of 38px) to account for the top and bottom padding (2px each).
  • However, Discourse adds a border to the element when it is hovered, causing the total width and height to change.
  • The border: 0px rule here doesn't have any effect because its specificity is still lower than the selector Discourse uses.

The fix is:

  • Changing the box model to border-box, so that padding and border are accounted into the width and height (meaning we or Discourse can adjust the padding and border, but the total width and height won't change).
  • Adding the !important flag to border: 0px to remove the border.
  • Updating the width and height values to account for the padding.
    • new value = original value + 2px * 2

@huyenltnguyen huyenltnguyen marked this pull request as ready for review April 19, 2024 08:36
@huyenltnguyen huyenltnguyen requested a review from a team as a code owner April 19, 2024 08:36
@raisedadead
Copy link
Member

Please merge and deploy when ready.

@huyenltnguyen huyenltnguyen merged commit 647308c into freeCodeCamp:main Apr 19, 2024
1 check passed
@huyenltnguyen huyenltnguyen deleted the fix/nav-items branch April 19, 2024 14:11
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.

2 participants