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

extend Each mixin #37

Closed
Punk-UnDeaD opened this issue May 30, 2016 · 12 comments
Closed

extend Each mixin #37

Punk-UnDeaD opened this issue May 30, 2016 · 12 comments

Comments

@Punk-UnDeaD
Copy link

Punk-UnDeaD commented May 30, 2016

@mixin each($num, $k=0) {
  &:nth-child(#{$num}n + #{$k}) {
    @content;
  }
}

for grid like this
|#|&|&|
|#|&|&|
we need clear:left on first col

@KittyGiraudel
Copy link
Contributor

I genuinely do not understand what you mean. Do you mind providing more information on what you are actually trying to achieve?

@LukyVj
Copy link
Owner

LukyVj commented May 30, 2016

Hey @Punk-UnDeaD I agree with @hugogiraudel, could you please add a bit more context and informations about your issue ?

I'm not sure I got it neither.

Thanks!

@Punk-UnDeaD
Copy link
Author

Punk-UnDeaD commented May 30, 2016

|#|&|&|
|#|&|&|
https://jsfiddle.net/83pjbrwj/

.foo {
  float: left;
  width: 33.33%;
  &:nth-child(3n+1){
    clear:left; 
  } 
}

I regularly use nth-child(3n+1)
but I do not remember the incidents of use only nth-child(3n)

https://jsfiddle.net/9gwy4t8e/

.foo {
  @include each(3){background: red;}
  &:nth-child(3n+1){background: green;}
  &:nth-child(3n+2){background: blue;}
}

It looks weird

@LukyVj
Copy link
Owner

LukyVj commented Jun 2, 2016

Hm, not sure what you mean.

@leonderijke
Copy link

I'm not sure what @Punk-UnDeaD means, but I do think the Each mixin can be extended. A use case would be to have an initial offset, to support "After 5 elements, each 3rd one":

@include each(3, 5) {
  /* styles */
}

would yield:

&:nth-child(3n + 5) {
   /* styles */
}

Possible solutions:

  • add $offset parameter to each
  • add each-from mixin

What do you think?

@leonderijke
Copy link

Scratch that, this is not how the nth-child selectors work. 😳

@LukyVj
Copy link
Owner

LukyVj commented Jun 2, 2016

I think you provided a really cool mixin :o !
I would create a new one tho, each-after($item, $offset).

I have a lot to do, I'll add this on the v1.0.5 this weekend!

@LukyVj
Copy link
Owner

LukyVj commented Jun 5, 2016

So, this is how the mixin could look like :

@mixin each-after($num, $offset) {
  &:nth-child(#{$offset}n) ~ li:nth-child(#{$num}n) {
    @content
  }
}

@LukyVj LukyVj closed this as completed in 5a42b8b Jun 5, 2016
LukyVj added a commit that referenced this issue Jun 5, 2016
LukyVj added a commit that referenced this issue Jun 5, 2016
@leonderijke
Copy link

Thanks, @LukyVj! Will try that out soon. It seems that this mixin hardcodes a li element selector, instead of referencing the parent with &. Is that on purpose?

@LukyVj
Copy link
Owner

LukyVj commented Jun 6, 2016

Wow, you're right! No it's not made on purpose, I was just tired and forgot to clean it :| Thanks for the heads up!

@LukyVj
Copy link
Owner

LukyVj commented Jun 6, 2016

So, after a lot of researches & tests, I'll remove it from this version, and I'll republish it on the next release.

@LukyVj
Copy link
Owner

LukyVj commented Jun 6, 2016

See : #61

I want to the $offset number to always be the first selected item.

It requires a little bit more magic & gymnastic than expected.

@LukyVj LukyVj reopened this Jun 6, 2016
LukyVj added a commit that referenced this issue Jun 6, 2016
LukyVj added a commit that referenced this issue Jun 6, 2016
LukyVj added a commit that referenced this issue Jun 6, 2016
LukyVj added a commit that referenced this issue Jun 6, 2016
LukyVj added a commit that referenced this issue Jun 6, 2016
LukyVj added a commit that referenced this issue Jun 6, 2016
* Fix #56

* Fixed twitter sharing message: more mixins :) (#58)

* Update file weight

* Remove each-after() mixin; See #37 & #61

* Remove each-after() mixin; See #37 & #61
LukyVj added a commit that referenced this issue Jun 6, 2016
* Fix #56

* Fixed twitter sharing message: more mixins :) (#58)

* Update file weight

* Remove each-after() mixin; See #37 & #61

* Remove each-after() mixin; See #37 & #61

* Fix <<<
LukyVj added a commit that referenced this issue Jun 6, 2016
* Fix #56

* Fixed twitter sharing message: more mixins :) (#58)

* Update file weight

* Remove each-after() mixin; See #37 & #61

* Remove each-after() mixin; See #37 & #61

* Fix <<<

* Update version and demo

* A few fixes + updated readme
@lachieh lachieh mentioned this issue Jun 6, 2016
This was referenced Jul 26, 2016
@LukyVj LukyVj closed this as completed in b00ddd1 Oct 25, 2016
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

4 participants