M
M
mixejuxix2019-10-04 09:44:13
css
mixejuxix, 2019-10-04 09:44:13

Is it possible to determine the elements from the last row in flexbox or count the number of elements in css?

Hello, help me, I'm making a mixin to create grids from a given number of columns and indent between them.
An example can be looked at - https://jsfiddle.net/yof4trp0/
But here's the problem - you need to remove the margin-bottom from the elements in the last line, otherwise it turns out ugly
Question: is it possible to somehow calculate the number of current elements inside the container? To do something like this:

&:nth-last-of-type(-n + abs($elemCount / $count)) {
    margin-bottom: 0;
}

Maybe there is some other way to remove the margin-bottom from the last line?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2019-10-04
@mixejuxix

Instead of margin-bottom, set margin-top , and set the first count elements to 0:

margin-top: $margin;

@for $i from 1 through $count {
  &:nth-child(#{$i}) {
    margin-top: 0;
  }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question