有没有一种方法可以编写在包含 mixins 之后总会出现的样式?
Is there a way to write style that will always come after mixins are included?
我遇到了 SCSS 混入问题,我必须重复相同的代码才能完成工作。我有以下 SCSS 代码:
@mixin column($count, $size) { // Can not make any change in this code.
width: getWidth($count, $size);
margin-left: 3%;
margin-right: 3%;
}
@mixin desktop {
@media screen and (min-width: 1024px) {
@content;
}
}
@mixin tablet {
@media screen and (min-width: 768px) and (max-width: 1023px) {
@content;
}
}
@function getWidth($count, $size) {
@return 50; // For example purpose only.
}
.c {
@include desktop {
@include column(10, large);
}
@include desktop {
@include column(11, large);
}
margin: 0 auto;
}
编译成:
.c {
margin: 0 auto;
}
@media screen and (min-width: 1024px) {
.c {
width: 50;
margin-left: 3%;
margin-right: 3%;
}
}
@media screen and (min-width: 1024px) {
.c {
width: 50;
margin-left: 3%;
margin-right: 3%;
}
}
这里的问题是 margin 被 mixins 覆盖了。或者我必须像下面一样重复相同的代码(重复代码):
.c {
@include desktop {
@include column(10, large);
margin: 0 auto; // Duplicate
}
@include desktop {
@include column(11, large);
margin: 0 auto; // Duplicate
}
margin: 0 auto;
}
获得:
.c {
margin: 0 auto;
}
@media screen and (min-width: 1024px) {
.c {
width: 50;
margin-left: 3%;
margin-right: 3%;
margin: 0 auto;
}
}
@media screen and (min-width: 1024px) {
.c {
width: 50;
margin-left: 3%;
margin-right: 3%;
margin: 0 auto;
}
}
有没有更好的方法来删除这些重复代码,让我只需要编写一次代码?
试试看 @media
查询是否让您满意。
.c {
@include desktop {
@include column(10, large);
}
@include desktop {
@include column(11, large);
}
& {
margin: 0 auto;
}
}
我遇到了 SCSS 混入问题,我必须重复相同的代码才能完成工作。我有以下 SCSS 代码:
@mixin column($count, $size) { // Can not make any change in this code.
width: getWidth($count, $size);
margin-left: 3%;
margin-right: 3%;
}
@mixin desktop {
@media screen and (min-width: 1024px) {
@content;
}
}
@mixin tablet {
@media screen and (min-width: 768px) and (max-width: 1023px) {
@content;
}
}
@function getWidth($count, $size) {
@return 50; // For example purpose only.
}
.c {
@include desktop {
@include column(10, large);
}
@include desktop {
@include column(11, large);
}
margin: 0 auto;
}
编译成:
.c {
margin: 0 auto;
}
@media screen and (min-width: 1024px) {
.c {
width: 50;
margin-left: 3%;
margin-right: 3%;
}
}
@media screen and (min-width: 1024px) {
.c {
width: 50;
margin-left: 3%;
margin-right: 3%;
}
}
这里的问题是 margin 被 mixins 覆盖了。或者我必须像下面一样重复相同的代码(重复代码):
.c {
@include desktop {
@include column(10, large);
margin: 0 auto; // Duplicate
}
@include desktop {
@include column(11, large);
margin: 0 auto; // Duplicate
}
margin: 0 auto;
}
获得:
.c {
margin: 0 auto;
}
@media screen and (min-width: 1024px) {
.c {
width: 50;
margin-left: 3%;
margin-right: 3%;
margin: 0 auto;
}
}
@media screen and (min-width: 1024px) {
.c {
width: 50;
margin-left: 3%;
margin-right: 3%;
margin: 0 auto;
}
}
有没有更好的方法来删除这些重复代码,让我只需要编写一次代码?
试试看 @media
查询是否让您满意。
.c {
@include desktop {
@include column(10, large);
}
@include desktop {
@include column(11, large);
}
& {
margin: 0 auto;
}
}