How to add different CSS style to every nth element, depending on n using LESS

后端 未结 2 1063
暖寄归人
暖寄归人 2021-01-18 23:06

I am trying to add different padding to subsequent elements in a div. My DOM looks pretty simple.

0
2条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-18 23:34

    Using less(but you have to set the num of elements):

    .parent (@indexstart,@index) when (@indexstart < @index ){
      div:nth-child(@{indexstart}){
        padding-left: (@indexstart - 1) * 15px;
      }
      .parent (@indexstart + 1,@index);
    }
    .parent (1,4);
    

    See example

提交回复
热议问题