Styles based on number of children

前端 未结 1 1282
情深已故
情深已故 2021-01-15 01:36

I have a container (.homepage-section) and inside this there could be up to three .widget\'s. Depending on how many .widget\'s there i

相关标签:
1条回答
  • 2021-01-15 02:40

    Try the following:

    .widget {
      @for $j from 2 through 5 {
        @for $i from 1 through $j {
          &:nth-of-type(#{$j + 1 - $i}):nth-last-of-type(#{$i}),
          &:nth-of-type(#{$j + 1 - $i}):nth-last-of-type(#{$i}) ~ .widget {
            width: (1000px / $j);
          }
        }
      }
    }
    

    (see the edited pen).

    The general rule — for each count of widgets, the sum of numbers in nth-* and nth-last-* must be the number of widgets plus 1, and the overall width must be divided by the number of widgets.

    0 讨论(0)
提交回复
热议问题