gpt4 book ai didi

css - 如何在每个循环中访问嵌套的多维列表

转载 作者:行者123 更新时间:2023-11-28 10:47:26 25 4
gpt4 key购买 nike

我正在尝试弄清楚如何使用 SASS 在每个循环中声明和访问嵌套列表。我想在第一个循环中使用第二个循环?

这是我的示例代码:

$chap1-blocks:  (5
(1, -70, 30),
(2, -130, 80),
(3, 10, -30),
(4, -90, 50)
),
(7
(1, -70, 30),
(2, -130, 80),
(3, 10, -30),
(4, -90, 50)
),
(10
(1, -70, 30),
(2, -130, 80),
(3, 10, -30),
(4, -90, 50)
);

@each $chap1-block in $chap1-blocks {
$section: nth($chap1-block, 1); //5
$row: nth($chap1-block, ??); //1
$top: nth($chap1-block, ??); //-70
$bottom: nth($chap1-block, ??); //30

.section-#{$section} {
.row-#{$row} {
margin: #{$top}px 0 #{$bottom}px;
}
}
}

第一组的期望输出:

.section-5 .row-1 {
margin: -70px 0 30px;
}
.section-5 .row-2 {
margin: -130px 0 80px;
}
.section-5 .row-3 {
margin: 10px 0 -30px;
}
.section-5 .row-4 {
margin: -90px 0 50px;
}

最佳答案

是的,您需要一个额外的循环,但您还需要以不同的方式将您的列表组合在一起。按照您的方式,您的内部列表中有 4 个元素,第一个元素是 5 (1, -70, 30) 的空格分隔列表。

$chap1-blocks:
( 5
( (1, -70, 30)
, (2, -130, 80)
, (3, 10, -30)
, (4, -90, 50)
)
, 7
( (1, -70, 30)
, (2, -130, 80)
, (3, 10, -30)
, (4, -90, 50)
)
, 10
( (1, -70, 30)
, (2, -130, 80)
, (3, 10, -30)
, (4, -90, 50)
)
);

@each $chap1-block in $chap1-blocks {
$section: nth($chap1-block, 1); //5
$rows: nth($chap1-block, 2);

.section-#{$section} {
@each $x in $rows {
$row: nth($x, 1); //1
$top: nth($x, 2); //-70
$bottom: nth($x, 3); //30
.row-#{$row} {
margin: #{$top}px 0 #{$bottom}px;
}
}
}
}

关于css - 如何在每个循环中访问嵌套的多维列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25559725/

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