我想创建自己的类似bootstrap的框架。但我遇到了一个问题。我创建了媒体查询部分,但无法使用Sass技术进行循环。我想做一个循环来完成以下
@media (min-width: #{/*there is the first loop (576px,768px,992px ..)*/}) {
.grid-col-#{/*this is loop two (i want to loop all sizes such (mid, xl, xxl))*/} {
display: grid;
grid-template-columns: repeat(#{/*i want here to make loop does take a lot of
numbers such as (1, 2, 3, 4, 5, 6 ..)
of columns*/},minmax(0, 1fr));
}
}
这个想法是让一个媒体重复,直到它携带所有尺寸的屏幕,就像这个
@media (min-width: 557px) {
.grid-col-sm-1 {
display: grid;
grid-template-columns: repeat(1 /*the number in the class*/, minmax(0, 1fr))
}
.grdi-col-sm-2 {
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr))
}
}
@media (min-width: 768px) {
.grid-col-md-1 {
display: grid;
grid-template-columns: repeat(1, minmax(0, 1fr))
}
.grid-col-md-2 {
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr))
}
}
我希望我解释得好。我只想发展我的基本技能。
您想要这样的东西:
$breakpoints : '575px','768px','992px','1200px';
@each $breakpoint in $breakpoints {
@media (min-width: #{$breakpoint} ) {
@for $i from 1 through 12 {
.grid-col-#{$i} {
display: grid;
grid-template-columns: repeat( #{$i},minmax(0, 1fr));
}
}
}
}
将输出:
@media (min-width: 575px) {
.grid-col-1 {
display: grid;
grid-template-columns: repeat(1, minmax(0, 1fr));
}
.grid-col-2 {
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
}
.grid-col-3 {
display: grid;
grid-template-columns: repeat(3, minmax(0, 1fr));
}
.grid-col-4 {
display: grid;
grid-template-columns: repeat(4, minmax(0, 1fr));
}
.grid-col-5 {
display: grid;
grid-template-columns: repeat(5, minmax(0, 1fr));
}
.grid-col-6 {
display: grid;
grid-template-columns: repeat(6, minmax(0, 1fr));
}
.grid-col-7 {
display: grid;
grid-template-columns: repeat(7, minmax(0, 1fr));
}
.grid-col-8 {
display: grid;
grid-template-columns: repeat(8, minmax(0, 1fr));
}
.grid-col-9 {
display: grid;
grid-template-columns: repeat(9, minmax(0, 1fr));
}
.grid-col-10 {
display: grid;
grid-template-columns: repeat(10, minmax(0, 1fr));
}
.grid-col-11 {
display: grid;
grid-template-columns: repeat(11, minmax(0, 1fr));
}
.grid-col-12 {
display: grid;
grid-template-columns: repeat(12, minmax(0, 1fr));
}
}
@media (min-width: 768px) {
.grid-col-1 {
display: grid;
grid-template-columns: repeat(1, minmax(0, 1fr));
}
.grid-col-2 {
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
}
.grid-col-3 {
display: grid;
grid-template-columns: repeat(3, minmax(0, 1fr));
}
.grid-col-4 {
display: grid;
grid-template-columns: repeat(4, minmax(0, 1fr));
}
.grid-col-5 {
display: grid;
grid-template-columns: repeat(5, minmax(0, 1fr));
}
.grid-col-6 {
display: grid;
grid-template-columns: repeat(6, minmax(0, 1fr));
}
.grid-col-7 {
display: grid;
grid-template-columns: repeat(7, minmax(0, 1fr));
}
.grid-col-8 {
display: grid;
grid-template-columns: repeat(8, minmax(0, 1fr));
}
.grid-col-9 {
display: grid;
grid-template-columns: repeat(9, minmax(0, 1fr));
}
.grid-col-10 {
display: grid;
grid-template-columns: repeat(10, minmax(0, 1fr));
}
.grid-col-11 {
display: grid;
grid-template-columns: repeat(11, minmax(0, 1fr));
}
.grid-col-12 {
display: grid;
grid-template-columns: repeat(12, minmax(0, 1fr));
}
}
@media (min-width: 992px) {
.grid-col-1 {
display: grid;
grid-template-columns: repeat(1, minmax(0, 1fr));
}
.grid-col-2 {
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
}
.grid-col-3 {
display: grid;
grid-template-columns: repeat(3, minmax(0, 1fr));
}
.grid-col-4 {
display: grid;
grid-template-columns: repeat(4, minmax(0, 1fr));
}
.grid-col-5 {
display: grid;
grid-template-columns: repeat(5, minmax(0, 1fr));
}
.grid-col-6 {
display: grid;
grid-template-columns: repeat(6, minmax(0, 1fr));
}
.grid-col-7 {
display: grid;
grid-template-columns: repeat(7, minmax(0, 1fr));
}
.grid-col-8 {
display: grid;
grid-template-columns: repeat(8, minmax(0, 1fr));
}
.grid-col-9 {
display: grid;
grid-template-columns: repeat(9, minmax(0, 1fr));
}
.grid-col-10 {
display: grid;
grid-template-columns: repeat(10, minmax(0, 1fr));
}
.grid-col-11 {
display: grid;
grid-template-columns: repeat(11, minmax(0, 1fr));
}
.grid-col-12 {
display: grid;
grid-template-columns: repeat(12, minmax(0, 1fr));
}
}
@media (min-width: 1200px) {
.grid-col-1 {
display: grid;
grid-template-columns: repeat(1, minmax(0, 1fr));
}
.grid-col-2 {
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
}
.grid-col-3 {
display: grid;
grid-template-columns: repeat(3, minmax(0, 1fr));
}
.grid-col-4 {
display: grid;
grid-template-columns: repeat(4, minmax(0, 1fr));
}
.grid-col-5 {
display: grid;
grid-template-columns: repeat(5, minmax(0, 1fr));
}
.grid-col-6 {
display: grid;
grid-template-columns: repeat(6, minmax(0, 1fr));
}
.grid-col-7 {
display: grid;
grid-template-columns: repeat(7, minmax(0, 1fr));
}
.grid-col-8 {
display: grid;
grid-template-columns: repeat(8, minmax(0, 1fr));
}
.grid-col-9 {
display: grid;
grid-template-columns: repeat(9, minmax(0, 1fr));
}
.grid-col-10 {
display: grid;
grid-template-columns: repeat(10, minmax(0, 1fr));
}
.grid-col-11 {
display: grid;
grid-template-columns: repeat(11, minmax(0, 1fr));
}
.grid-col-12 {
display: grid;
grid-template-columns: repeat(12, minmax(0, 1fr));
}
}