gpt4 book ai didi

css - 如何创建支持内容 block 的 Sass mixin 别名?

转载 作者:行者123 更新时间:2023-12-01 17:50:00 25 4
gpt4 key购买 nike

如何为同一个 mixin 定义多个名称,并支持内容 block ?

定义

@mixin desktop-breakpoint {
@media only screen and (min-width: 769px) {
@content;
}
}

@mixin large-breakpoint {
@include desktop-breakpoint;
}

使用

.my-class {
font-size: small;

@include desktop-breakpoint {
font-size: big;
}
}

.my-other-class {
color: red;

@include large-breakpoint {
color: blue;
}
}

错误消息

Mixin "large-breakpoint" does not accept a content block.

最佳答案

large-breakpoint mixin 中使用 @includedesktop-breakpoint 时,您没有传递任何 @content。这样做将修复您的编译错误:

@mixin large-breakpoint {
// Remember to pass content received by mixin to @include
@include desktop-breakpoint {
@content;
}
}

然后你的 CSS 将按照预期正确编译:

.my-class {
font-size: small;
}
@media only screen and (min-width: 769px) {
.my-class {
font-size: big;
}
}

.my-other-class {
color: red;
}
@media only screen and (min-width: 769px) {
.my-other-class {
color: blue;
}
}

查看基于您修改后的代码的概念验证示例:https://www.sassmeister.com/gist/3109af060293eed0b89a22c27fa20527

关于css - 如何创建支持内容 block 的 Sass mixin 别名?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50038602/

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