【发布时间】:2016-12-17 09:40:57
【问题描述】:
所以我希望有人可以帮助我解决一些看起来简单的事情。
我设置了一个网格模板,其中包含不同位置的广告。导致代码结构有点复杂。基本上现在对我来说,为了让它看起来恰到好处,我使用了相当多的 &:nth-child 选择器来删除 / 各个断点处的广告边距。
而不是我写出以下内容:
&:nth-child( 3 ),
&:nth-child( 10 ),
&:nth-child( 13 ),
&:nth-child( 17 ),
&:nth-child( 20 ),
&:nth-child( 23 ),
&:nth-child( 26 ),
&:nth-child( 30 ),
&:nth-child( 33 ),
&:nth-child( 37 ),
&:nth-child( 43 ) {
margin-right: $gutter-width;
}
我一直在尝试创建一个混合,允许我传递一个整数数组,并让 css 通过调用类似于
的内容来吐出我上面显示的内容@include nth-children( 3, 10, 13, 17, 20...) {
margin-right: $gutter-width;
}
唯一的问题是我还需要能够传递一个方程式作为该列表的一部分 (20n - 5) 或任何情况。
我尝试了一些方法,但似乎无法接近
@mixin nth-children($nths) {
@for $i from 1 through length($nths) {
&:nth-child(#{$i}) {
@content;
}
}
}
我想防止首先创建一个列表,因为值会在多种不同的屏幕尺寸和页面布局上不断变化。
【问题讨论】:
标签: css arrays sass css-selectors