Jeet column() mixin overflow when nested with zero gutters
0 reputation · 29 Aug 2023, 17:29 UTC
0 reputation · 29 Aug 2023, 17:29 UTC
When nesting Jeet’s column() mixin inside a container where gutters() is set to 0px, the calculated width of the inner columns can exceed the parent’s width, causing horizontal overflow.
The problem appears specifically when the inner columns also use shift() or the spread option, and its severity differs between Ruby Sass and LibSass (notably LibSass 3.5.x). Although Jeet’s documentation states that zero‑gutter layouts are supported, the example omits the required reset‑gutters() call that would prevent the miscalculation.
31775 reputation · 29 Aug 2023, 21:10 UTC
1. Invoking reset‑gutters() correctly
When a parent row has been declared with gutters(0), the gutter context for any nested rows is zero. If you need to nest a row() inside that parent and the inner column() declarations use shift() or the spread option, call reset‑gutters() immediately before the nested row():
@include gutters(0); // parent row
@include reset-gutters(); // restore Jeet’s default gutter
@include row(); // nested row
@include column(6, shift(1)); // inner column
After reset‑gutters(), the gutter context reverts to Jeet’s default (usually 30px). The nested row then calculates column widths relative to that default. If you still want the visual appearance of zero gutters inside the nested row, re‑apply gutters(0) right after the row() declaration:
@include row();
@include gutters(0); // zero‑gutter inside nested row
Because reset‑gutters() changes the gutter for all subsequent selectors until overridden, it is important to re‑apply gutters(0) only inside the nested block where zero gutters are desired.
In practice, the sequence reset‑gutters(); row(); gutters(0); column(...) has been observed to eliminate horizontal overflow caused by shift() or spread() when compiling with LibSass 3.5.x. The fix works because the width calculations use the restored gutter baseline, preventing the inner columns from exceeding the parent’s width. However, because Sass engine behavior can vary between releases, it is prudent to verify the compiled CSS in your target environment.
Creating a small wrapper mixin that automatically performs the reset‑gutters() call followed by row() (and optionally gutters(0)) is a practical way to encapsulate this pattern. It keeps the gutter context local to the nested row and reduces the risk of leaking the default gutter into unrelated sibling blocks. The wrapper can be reused across both Ruby Sass and LibSass implementations, providing a uniform approach.
When using such a wrapper, remember to:
gutters(0) inside the wrapper if the nested layout must remain zero‑gutter.
To determine whether the reset‑gutters() step is necessary for your particular markup, could you confirm whether any of the inner column() declarations use shift() or the spread option?
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.