代码之家  ›  专栏  ›  技术社区  ›  JacobTheDev

在同级导入文件中扩展类无效

  •  0
  • JacobTheDev  · 技术社区  · 7 年前

    我想用Sass的 @extend

    在里面 _title.scss

    .title { font-family: "Open Sans"; }
    

    _user-content.scss

    .user-content { h1, h2, h3, h4, h5, h6 { @extend .title; } }
    

    在里面 screen.scss :

    @import "_title";
    @import "_user-content";
    

    运行时 gulp-sass

    [13:15:02] gulp-notify: [Gulp] src/assets/styles/base/user-content/_user-content.scss
    Error: ".user-content h1" failed to @extend ".title".
           The selector ".title" was not found.
           Use "@extend .title !optional" if the extend should be able to fail.
            on line 1 of src/assets/styles/base/user-content/_user-content.scss
    >> .user-content { h1, h2, h3, h4, h5, h6 { @extend .title; } }
       -----------------------------------------^
    

    在我看来这似乎是正确的,但这是一个错误。我做错了什么?

    2 回复  |  直到 7 年前
        1
  •  0
  •   Alex Bieg    7 年前

    我认为您需要将“标题”导入“用户内容”。我不确定您是否可以从另一个导入的文件中访问导入的类。

        2
  •  0
  •   JacobTheDev    7 年前

    好吧,我只是在装傻。我忘了我有两个SCSS文件,一个 screen.scss editor.scss .导入在 ,但失败了 ,因为我没有导入我试图扩展到的类 编辑器.scss