Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to include @mixin from one sass file to another sass file in different folder.

Tags:

css

sass

ionic3

I am including a mixin from one SASS file into another file but I've got an error with the ionic serve command:

Error: "Sass Error
Invalid CSS after " @include": expected identifier, was '"../../../theme/mai'"

This is the file where I am importing the mixin:

action-sheet-layout-1 { 
    @include '../../../theme/main.scss' 
    @include "settingAnimationHeader"; // this mixin is defined in main.scss

    [button-action-shit] {
        z-index: 99999; right: 16px; top: 56px;
        ...
    }

The mixin as defined in main.scss:

@mixin settingAnimationHeader { 
    @keyframes headerOff { 
        from { 
            background-color: theme-colors('mainColors', 'primary'); 
        } 
        to {
            background-color: transparent;
        } 
    }
...
}

I am new to ionic and SASS, is what I am doing right or am I missing something?

The directory structure of both files from the app root:

src/theme/main.scss # the mixin is defined in this file.
src/components/action-sheet/layout-1/action-sheet-layout-1.scss # the mixin is imported here.
like image 857
Abhitesh khatri Avatar asked Mar 20 '18 19:03

Abhitesh khatri


People also ask

How use Sass variable from another file?

To use variables across multiple files in SASS is carried out by @import rule of SASS. @import rule which import Sass and CSS stylesheets for providing variables, @mixins and functions. Such that combine all stylesheets together for compiled css. It also imports URL such as frameworks like Bootstrap etc..

Can you import SCSS into Sass?

Sass extends CSS's @import rule with the ability to import Sass and CSS stylesheets, providing access to mixins, functions, and variables and combining multiple stylesheets' CSS together.

What is the difference between @import and @USE in SCSS?

The new @use rule is the replacement for @import which allows other stylesheets to use its variables, functions, and mixins. What makes the @use import different is that the module (file imported using @use ) is only imported once, no matter how many times you reference it in your project.

Which directive is used to convert multiple Sass into single or multiple CSS files?

Sass Importing Files Just like CSS, Sass also supports the @import directive. The @import directive allows you to include the content of one file in another.


1 Answers

at the top of your SASS file (action-sheet-layout-1.scss) you need to include: @import "../../../theme/main.scss" then you can access the mixins inside main.scss by doing @include settingAnimationHeader; inside the css rule where you want to apply this mixin

like image 173
philr Avatar answered Oct 04 '22 02:10

philr