Using outline instead of border to avoid the layout to shift #50
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR replaces the use of a border for the highlight effect with an outline. The primary goal is to achieve a visually similar highlight effect (5px solid lime) while avoiding layout shifts that occur when using borders.
Details
Borders are part of the element’s box model. When a border is applied, it increases the element’s total dimensions, which can cause surrounding elements to shift or reflow. This is particularly problematic in dynamic layouts or when toggling states, as it may lead to an inconsistent user experience.
Outlines, on the other hand, are not included in the box model. They are drawn on top of the element without affecting its dimensions. This means that applying an outline will not cause any layout reflows or shifts, ensuring that the UI remains stable regardless of whether the highlight is active or not.
Implementation:
The CSS changes include:
The
outline-offset: -5px
is used here to simulate the effect of an inner highlight, ensuring that the outline appears inside the element, giving it a “highlight-y” effect without modifying its size.Impact
By using an outline instead of a border, this update:
Let me know if any further adjustments are needed.