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

Flow items are mis-aligned to grid #18

Closed
JohnAlbin opened this issue May 3, 2012 · 0 comments
Closed

Flow items are mis-aligned to grid #18

JohnAlbin opened this issue May 3, 2012 · 0 comments
Labels

Comments

@JohnAlbin
Copy link
Owner

There's an error in the calculations of the flow items when using the zen-grid-flow-item() mixin. The problem is that the parent element width is exactly 1 gutter width smaller than the width of the columns it spans. So the % width of the flow items is relative to the wrong measurement.

Spent some time trying to fix this and I believe the following replacement should work.


@mixin zen-grid-flow-item (
  $column-span,
  $parent-column-count: false,
  $alpha-gutter: false,
  $omega-gutter: true,
  $flow-direction: $zen-float-direction,
  $column-count: $zen-column-count,
  $gutter-width: $zen-gutter-width,
  $grid-width: $zen-grid-width,
  $box-sizing: $zen-box-sizing,
  $reverse-all-flows: $zen-reverse-all-floats,
  $auto-include-flow-item-base: $zen-auto-include-flow-item-base
) {

  $columns: $column-count;
  @if unit($grid-width) == "%" {
    @if $parent-column-count == false {
      @warn "For responsive layouts with a percentage-based grid width, you must set the $column-count to the number of columns that the parent element spans.";
    }
    @else {
      $columns: $parent-column-count;
    }
  }

  $dir: $flow-direction;
  @if $reverse-all-flows {
    $dir: zen-direction-flip($dir);
  }
  $rev: zen-direction-flip($dir);

  // Calculate the item's width.
  $width: zen-grid-item-width($column-span, $columns, $grid-width);
  @if $box-sizing == content-box {
    @if not comparable($width, $gutter-width) {
      $units-gutter: unit($gutter-width);
      $units-grid: unit($grid-width);
      @warn "The layout cannot be calculated correctly; when using box-sizing: content-box, the units of the gutter (#{$units-gutter} did not match the units of the grid width (#{$units-grid}).";
    }
    $width: $width - $gutter-width;
  }
  width: $width;

  // Auto-apply the unit base mixin.
  @if $auto-include-flow-item-base {
    @include zen-grid-item-base($gutter-width, $box-sizing);
  }

  // Ensure the HTML item either has a full gutter or no gutter on each side.
  padding-#{$dir}: 0;
  @if $alpha-gutter {
    margin-#{$dir}: $gutter-width;
  }
  $offset: ($columns - $column-span) * $gutter-width / $columns;
  padding-#{$rev}: $offset;
  @if $omega-gutter {
    margin-#{$rev}: $gutter-width - $offset;
  }
  @else {
    margin-#{$rev}: -($offset);
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant