0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

nth区切りのdivをつくる。

Last updated at Posted at 2018-03-02

こういうのに遭遇する度にわすれているのでメモ📝

実現したいこと

3個区切りの <div> のまとまりをつくる。
最後のまとまりは 3個じゃなくても閉じる。
スライドショーなどの実装に。
 
例👇
image.png

ソース

ここではTwigを使用。


{% set no = 0 %}
{% set lists = ['a','a','a','a','a','a','a','a','a','a','a'] %} ※11個の配列
{% set listsLength = lists|length %}

{% for list in lists %}
  {% set no = no + 1 %}
    {% if ( no%3 == 1 ) %} 
     <div class="test-wrap">
    {% endif %}

      <p>item {{ no }}</p>

    {% if ( no%3 == 0 ) %}
      </div>
    {% elseif (listsLength == no)  %}
      </div>
    {% endif %}

{% endfor %}

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?