From f2528364469b42b31170e23a22b177fee6443a67 Mon Sep 17 00:00:00 2001 From: Geoff Kimball Date: Thu, 14 Jan 2016 17:28:01 -0800 Subject: [PATCH] Add grid-layout-center-last() mixin to center last items in block grid, closes #7807 --- scss/grid/_layout.scss | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/scss/grid/_layout.scss b/scss/grid/_layout.scss index e88d8cd87..9f5da07c2 100644 --- a/scss/grid/_layout.scss +++ b/scss/grid/_layout.scss @@ -31,3 +31,21 @@ } } } + +/// Adds extra CSS to block grid children so the last items in the row center automatically. Apply this to the columns, not the row. +/// +/// @param {Number} $n - Number of items that appear in each row. +@mixin grid-layout-center-last($n) { + @for $i from 1 to $n { + @if $i == 1 { + &:nth-child(#{$n}n+1):last-child { + margin-left: (100 - 100/$n * $i) / 2 * 1%; + } + } + @else { + &:nth-child(#{$n}n+1):nth-last-child(#{$i}) { + margin-left: (100 - 100/$n * $i) / 2 * 1%; + } + } + } +} -- 2.47.2