Repeat dots in LESS / SASS for Content property

前端 未结 3 1406
慢半拍i
慢半拍i 2021-01-19 02:20

Take a look at below CSS styles and i\'m planning to use LESS & SASS for two different projects and is this possible in preprocessors.

.long         


        
3条回答
  •  北海茫月
    2021-01-19 03:04

    LESS

    Based on Seika85's answer, I've created a more generalized function for repeating an input arg with your choice of delimiter:

    .repeater(@item, @count, @delimiter: " ", @iterated-item: "") when (@count = 1) {
      @return: ~'@{iterated-item}@{item}';
    }
    .repeater(@item, @count, @delimiter: " ", @iterated-item: "") when (@count > 1) {
      .repeater(@item, (@count - 1), @delimiter, ~'@{iterated-item}@{item}@{delimiter}');
    }
    

    Usage:

    div {
      background-image: .repeater(url(foo.svg), 5, ", ")[];
    }
    

    Compiles to:

    div {
      background-image: url(foo.svg), url(foo.svg), url(foo.svg), url(foo.svg), url(foo.svg);
    }
    

提交回复
热议问题