Skip to content

Instantly share code, notes, and snippets.

@ln-north
Created March 9, 2020 12:54
Show Gist options
  • Select an option

  • Save ln-north/afdd3a0fd3b93d7a7ebcd4fde9ba6a89 to your computer and use it in GitHub Desktop.

Select an option

Save ln-north/afdd3a0fd3b93d7a7ebcd4fde9ba6a89 to your computer and use it in GitHub Desktop.
親が flex-flow: row wrap なときにいい感じで横並びするやつ
// 親が flex-flow: row wrap なときにいい感じで横並びするやつ
@mixin align-cell($row: 4, $gap-horz: 20px, $gap-vert: 20px) {
width: calc(100% / #{$row} - #{$gap-horz * ($row - 1) / $row});
& + & {
margin-left: $gap-horz;
}
&:nth-of-type(n + #{$row + 1}) {
margin-top: $gap-vert;
}
&:nth-of-type(#{$row}n + 1) {
margin-left: 0;
}
@for $var from 1 to $row {
// 改行が発生する場合最後の要素にmarginをつけて左寄せにする
// 改行しない場合は何もしない
&:nth-of-type(n + #{$row + 1}):nth-of-type(#{$row}n + #{$var}):last-of-type {
margin-right: calc((100% / #{$row} - #{$gap-horz * ($row - 1) / $row}) * #{$row - $var} + #{$gap-horz} * #{$row - $var});
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment