gpt4 book ai didi

css - Rails 4.0 每 3 个 div 循环然后应用类

转载 作者:行者123 更新时间:2023-12-02 15:27:11 25 4
gpt4 key购买 nike

我在下面循环

- @published_only.each do |p|
.movie.effect
= image_tag(p.poster_url(:thumb), class: "img")
.mini-desc
%h4= p.title

它会给

<div class="movie effect>...</div>
<div class="movie effect>...</div>
<div class="movie effect>...</div>
<div class="movie effect>...</div>
<div class="movie effect>...</div>
<div class="movie effect>...</div>

如何让它为每 3 个 div 应用“最后一个”类。例如:

<div class="movie effect>...</div>
<div class="movie effect>...</div>
<div class="movie effect last>...</div>
<div class="movie effect>...</div>
<div class="movie effect>...</div>
<div class="movie effect last>...</div>

最佳答案

您可以使用 cycle方法:

.movie.effect{class: cycle('', '', 'last')}

关于css - Rails 4.0 每 3 个 div 循环然后应用类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29793533/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com