- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个基本的 HTML 结构,其中每行显示 3 个项目。为了正确分隔它们,我使用了 2 个边框(第一个/第二个/第二个/第三个),如下图所示:
ITEM1 | ITEM2 | ITEM3
使用 SASS 定义如下:
.middle {
position: relative;
z-index: 1;
&:before {
content: '';
width: 32px;
height: 100%;
position: absolute;
left: -24px;
top: 0;
display: block;
z-index: -1;
box-shadow: 32px 0 0 0 #fff, 0 -32px 0 0 #fff, 0 32px 0 0 #fff, 32px 32px 0 0 #fff, 32px -32px 0 0 #fff, 0 0 32px 0 rgba(0, 0, 0, 0.15);
}
&:after {
content: '';
width: 32px;
height: 100%;
position: absolute;
right: -24px;
top: 0;
display: block;
z-index: -1;
box-shadow: -32px 0 0 0 #fff, 0 -32px 0 0 #fff, 0 32px 0 0 #fff, -32px 32px 0 0 #fff, -32px -32px 0 0 #fff, 0 0 32px 0 rgba(0, 0, 0, 0.15);
}
}
当我迭代 Jekyll 集合时,我想区分这 3 行项目。换句话说,迭代第 3 项和第 3 项。 它我几个小时前才开始研究 Jekyll,我可以看到 filters are available ,但我不知道如何在标准集合迭代中实现这一点,如下所示:
{% for item in array %}
{{ item }}
{% endfor %}
最佳答案
为了能够在迭代时将项目分组到一行中,我们使用 modulo
过滤器:
Divides an output by a number and returns the remainder.
然后我们可以通过执行 forloop.index | 来识别每个迭代,更具体地说,我们正在处理三个项目中的哪一个。模数:3
:
如果余数为1,则为该行的第一项,如果为2,则为第二项,如果为0,则为第三项。例如遍历数组 site.posts
{% for post in site.posts %}
{% assign mod = forloop.index | modulo: 3 %}
{{ mod }}:{{post.title}}
{% if mod == 1 %}
<div>first item</div>
{% elsif mod == 2 %}
<div class="middle">second item</div>
{% else %}
<div>third item</div>
<hr>
{% endif %}
<br>
{% endfor %}
请注意,根据您的代码,我已将 middle
css 类应用于第二个项目。
这将输出:
1:First post title
first item
2:Second post title
second item
0:Third post title
third item
-----------------
1:Fourth post title
first item
关于jekyll - 我如何以 3 批处理迭代 Jekyll/Liquid 集合项目?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43098107/
我的理解是 Liquid 将 Ruby 哈希转换为用于标签的数组。例如,当使用 Jekyll 时: {% for category in site.categories %} {{ categ
如何使用两个参数编写/调用自定义液体标签? 上下文:Jekyll 2.1.1 我有一些页面显示为选项卡集。我的页面前端可以为某些页面定义额外的选项卡,如下所示: --- blah: blah extr
谁能指出支持的 Jekyll Liquid 标签的最终列表? 我知道来自 https://github.com/mojombo/jekyll/wiki/liquid-extensions 的 {{ c
我已经用液体编写了一个自定义标签,我想将一个变量传递给它。 Liquid 标签会将任何参数转换为字符串。 例如: {% nav page /some/url.html %} 其中 page 是一个变量
我正在尝试为我的帖子下方的导航链接做一个循环。这是进入posts.html的_layout 我无法获得不显示帖子是最后一个还是第一个的链接。任何帮助都是极好的。 {% 用于 site.posts 中的
如何在 Liquid 中跳出循环,主要是 for 循环?我试过 {% break %} ,但失败并显示保存文件时出错:未知标签“中断”。 我正在尝试实现以下目标: var variants = [];
有谁知道 Azure 在逻辑应用程序的 Liquid 连接器中使用什么风格的 Liquid 模板引擎?我们的印象是它是 DotLiquid,但事实似乎并非如此。 有液体连接器的源代码吗? 最佳答案 它
我有以下液体标记: {{ 'image.jpg' | theme_image_tag }} 它的渲染效果如下: 如何向其中添加类或任何选项?我希望它呈现如下: 我使用 Locomotive CMS
当我在 Windows 10 上运行命令 bundle exec jekyllserve --trace 时,出现以下错误: Liquid Exception: Liquid syntax error
当我在 Windows 10 上运行命令 bundle exec jekyllserve --trace 时,出现以下错误: Liquid Exception: Liquid syntax error
我正在尝试将 JS 文件合并到一个文件中,但是我需要使用 js 文件中的 if 语句设置条件。 我已经创建了 file.js.liquid 但它似乎不起作用;例如,我添加了一个测试: {% if te
我最近按照本教程中的以下步骤概述将 Liquid Fire 添加到我的 Ember CLI 0.2.3 项目中:http://www.programwitherik.com/doing-animati
我有一个jekyll网站,并且有一个类别(称为photo),我想为页面创建一个单独的布局,该页面仅列出photo类别中的帖子。我还想将photo类别的帖子保留在主索引页面之外。 最佳答案 所有类别都可
我正在 Jekyll 中编写一个网站,它使用 Liquid。 我希望页面的正面内容看起来像这样: --- title: Designing algorithms that scale horizont
我在 for 循环中提取元数据值,需要将它们显示在逗号分隔列表中。 代码(为便于阅读而添加的空格): {% if asset.metadata['field01'] %}{{asset.metadat
我正在使用 Shopify 并想连接到客户标签,但它们区分大小写。因此 {% if customer.tags contains "wholesale"%} 与 {% if customer.tags
我正在为我的商店开发一个新的 Shopify 模板。我正在尝试将标题中的字符数和描述中的字符数相加。从 200 中减去这个总数,并在我的截断中使用结果。 (这是因为我想在每个框中获得相同数量的字符)
在一个简单的 Jekyll 站点中,我有一个如下所示的菜单: Home Page 1 Page 2 Page 3 当我输出 page.url在这个块之前或之后,它总
我接到了一个小任务,为 Shopify 上制作的主题添加功能。我擅长 PHP,但 shopify 使用 .liquid 文件。 我想知道它是如何像这个代码片段一样工作的 {{% if payment.
我正尝试在 Shopify 和 less 中使用很棒的字体。我将 less 文件编译成 css 并添加了以下图标。 .icon-caret-down:before { content: "\f0d
我是一名优秀的程序员,十分优秀!