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

Add first-row last-row mixins #9

Open
nirazul opened this issue Sep 16, 2016 · 6 comments
Open

Add first-row last-row mixins #9

nirazul opened this issue Sep 16, 2016 · 6 comments

Comments

@nirazul
Copy link

nirazul commented Sep 16, 2016

Thanks for the nice compilation of mixins!
I think it would be a cool addition to also implement first-row and last-row mixins displayed in this article.

I occasionally use this mixin for targeting last rows:

/// Targets the last row in a grid of constant column count
/// @link http://keithclark.co.uk/articles/targeting-first-and-last-rows-in-css-grid-layouts/
/// @param {number} $num-cols - The number of columns within the context
///
@mixin last-row($num-cols) {
  $selector: nth(nth(&, 1), length(nth(&, 1)));

  &:nth-child(#{$num-cols}n + 1):nth-last-child(-n + #{$num-cols}),
  &:nth-child(#{$num-cols}n + 1):nth-last-child(-n + #{$num-cols}) ~ #{$selector} {
    @content;
  }
}

/// Usage
///
ul > li {
  @include last-row(2) {
    color: red
  }
}
@danielguillan
Copy link
Owner

Very interesting. I'll take a look at it. Thanks for the suggestion @nirazul!

@robsonsobral
Copy link
Contributor

I've found a use for that!

    &:last-child {
      border-bottom: 0;
    }

    @media screen and(min-width: 40.5em) { // 648px
      @include my.last-row(2) {
        border-bottom: 0;
      }
    }

    @media screen and(min-width: 59.25em) { // 948px
      @include my.last-row(3) {
        border-bottom: 0;
      }
    }

@robsonsobral
Copy link
Contributor

@danielguillan , would you accept a PR?

@robsonsobral
Copy link
Contributor

@danielguillan ?

@robsonsobral
Copy link
Contributor

I did some tests.

Based on this article, we could have something like:

ul > li {
    @include first(4) { color: red; }
}

ul > li {
    @include last(6) { color: blue; }
}

ul > li {
    @include last-or-remainder(6) { color: blue; }
}
ul > li:nth-child(-n+4) {
  color: red;
}

ul > li:nth-child(6n+1):nth-last-child(-n+6) {
  color: blue;
}

ul > li:nth-child(6n+1):nth-last-child(-n+6),
ul > li:nth-child(6n+1):nth-last-child(-n+6) ~ li {
  color: blue;
}

However, in these cases the total quantity doesn't matter, so... I'm not sure these mixins have a place in here. I think they do, but I'm not the boss.

@robsonsobral
Copy link
Contributor

Don't you want another PR, @danielguillan ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants