gpt4 book ai didi

function - Sass 使用伪选择器扩展

转载 作者:太空宇宙 更新时间:2023-11-03 17:52:37 25 4
gpt4 key购买 nike

我在 mac osx 上使用 compass 管理一些 sass 文件。我有这些文件:

sass/
screen.scss
partials folder/
...
_fonts.scss
_functions.scss
...

在字体中我有这个规则,我想重用@extend。

//fonts.scss
.icon-ab-logo, {
font-family: 'icomoon';
speak: none;
font-style: normal;
font-weight: normal;
font-variant: normal;
text-transform: none;
line-height: 1;
-webkit-font-smoothing: antialiased;
}
.icon-ab-logo:before { //i want to reuse this.
content: "\e000";
}

在函数中我有这个 screen.scss:

.logo {
position: absolute;
top: 0;
bottom: 0px;
z-index: 500;
width: 9.5em;
background: $logo;
@include transition(all 0.2s);
&:after{
@include icon( ".icon-ab-logo" );
}
}

最后在 functions.scss 中我称之为:

    @mixin icon( $icon ){
font-family: 'icomoon';
speak: none;
font-style: normal;
font-weight: normal;
font-variant: normal;
text-transform: none;
line-height: 1;
-webkit-font-smoothing: antialiased;
@extend #{$icon}:before; //<- this is the problem, no errors just isn't parsed.
}

有没有办法在使用 mixin 之前引用 .icon-ab-logo: ?解决方法?感谢阅读。

最佳答案

当您想扩展伪类或伪元素时,您只想扩展父选择器(即冒号之前的所有内容)。

%foo:before {
color: red;
}

.bar {
@extend %foo;
}

生成:

.bar:before {
color: red;
}

所以对于你的例子,你想要做的是:

.icon-ab-logo, {
font: 100%/1 'icomoon'; // use the shorthand
speak: none;
text-transform: none;
-webkit-font-smoothing: antialiased;
}

%foo:before, .icon-ab-logo:before { //i want to reuse this.
content: "\e000";
}

@mixin icon( $icon ){
font: 100%/1 'icomoon'; // use the shorthand
speak: none;
text-transform: none;
-webkit-font-smoothing: antialiased;
@extend #{$icon};
}

.bar {
@include icon('%foo');
}

请注意,您的 mixin 会生成很多 样式,因此它不太适合广泛重用。扩展它也会更有意义。

关于function - Sass 使用伪选择器扩展,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27014882/

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