Sass 如果在每个里面
Posted
技术标签:
【中文标题】Sass 如果在每个里面【英文标题】:Sass if inside each 【发布时间】:2014-09-25 03:30:39 【问题描述】:我正在尝试从以下列表中获取特定的选择器,以获得两个属性,而所有其他选择器只有一个属性。
我尝试了以下代码,但似乎每个选择器都获取了在 if 函数内的类上定义的两个属性。
$items: (one 20% 30%) (two 12% 24%) (three 34% 32%) (four 45% 50%);
@each $item in $items
@if #nth($item, 1) == one or three
.#nth($item, 1)
left: #nth($item, 2);
bottom: #nth($item, 3);
@else
.#nth($item, 1)
left: #nth($item, 2);
我想要达到的结果是:
.one
left: 20%;
bottom: 30%;
.two
left: 12%;
.three
left: 34%;
bottom: 32%;
.four
left: 45%;
【问题讨论】:
【参考方案1】:问题在于你的逻辑。您的 if 语句有 2 个表达式:(nth($item, 1) == one) or (three)
。 three
部分始终评估为真。
$items: (one 20% 30%) (two 12% 24%) (three 34% 32%) (four 45% 50%);
@each $item in $items
@if nth($item, 1) == one or nth($item, 1) == three
.#nth($item, 1)
left: #nth($item, 2);
bottom: #nth($item, 3);
@else
.#nth($item, 1)
left: #nth($item, 2);
【讨论】:
以上是关于Sass 如果在每个里面的主要内容,如果未能解决你的问题,请参考以下文章