【发布时间】:2015-07-16 18:48:23
【问题描述】:
我希望能够根据 YAML 前文中定义的颜色设置帖子的背景颜色。
这个主题做到了:Single Paged (github here)
但我无法理解它是如何完成的。 CSS 文件中的这段代码是它发生的原因:
{% for c in site.colors %}
.border-{{c[0]}} { border-color: {{ c[1] }} !important; }
.text-{{c[0]}} { color: {{ c[1] }}; }
.text-{{c[0]}} a { color: {{ c[1] }}; }
.bg-{{c[0]}} { background-color: {{ c[1] }} !important; }
{% endfor %}
/* ----- per-post colors! ----- */
{% for node in site.posts %}
{% capture id %}{{ node.id | remove:'/' | downcase }}{% endcapture %}
{% capture bg %}{% if site.colors[node.bg] %}{{ site.colors[node.bg] }}{% else %}{{ node.bg }}{% endif %}{% endcapture %}
{% capture fg %}{% if site.colors[node.color] %}{{ site.colors[node.color] }}{% else %}{{ node.color }}{% endif %}{% endcapture %}
nav .p-{{id}} { border-color: {{ bg }}; }
#{{id}} { background-color: {{ bg }} !important; color: {{ fg }}; }
#{{id}} a { color: {{ fg }}; }
#{{id}} .sectiondivider { color: {{ bg }}; }
{% endfor %}
这是 CSS 中的 Liquid 吗?有人可以引导我完成代码吗? 谢谢!
【问题讨论】: