css increment nth-child attribute values

依然范特西╮ 提交于 2019-12-05 05:34:38

You could if you use a preprocessor like sass.

An example:

div {
  $var: 5;

  @for $i from 1 through 5 {
    &:nth-child(#{$i}) {
      top: -#{$var}px;
      $var: $var + 5;
    }
  }
}

A demo: http://sassmeister.com/gist/7d7a8ed86e857be02d1a

Another way to achieve this:

div {

  $list: 1 2 3 4 5;

  @each $i in $list {
    &:nth-child(#{$i}) {
      top: -5px * $i;
    }
  }
}

A demo: https://www.sassmeister.com/gist/fb5ee7aa774aafb896cd71a828882b99

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!