Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sass Modularity -- Import additional partial within in a media query partial

Everybody (hopefully) strives for code modularity. What I am trying to do is have 1 main Sass file which imports all of my modules, which are partials, and these partials can call their own groups of partials if need be. What I would like is, instead of calling media queries all over my codebase (as described here: http://css-tricks.com/media-queries-sass-3-2-and-codekit/), have one media.sass file which manages all the different styles for each module's different screen sizes.

Here is my file structure for the Sass files:

    sass
      | styles.sass
      | _media.sass
      | base
          | _variables.sass
          | _mixins.sass
      | menu
          | _menu.sass
          | _menu_mobile_portrait.sass
      | modal
          | _modal.sass
          | _modal_mobile_portrait.sass

Here is my main Sass file:

styles.sass

    @import "base/variables"
    @import "base/mixins"
    @import "menu"
    @import "modal"
    ...
    @import "media"

The last line here is aimed at _media.sass, which I would LIKE to look like this:

    // #Mobile (Portrait)
    // ==================================================

        // Note: Design for a width of 320px

        @media only screen and (max-width: 767px)
          @import "menu/menu_mobile_portrait"
          @import "modal/modal_mobile_portrait"

Using the latest CodeKit, the files compile without any errors; however, the nested, imported modules in the media file don't show up in the compiled CSS.

like image 650
rpearce Avatar asked Jun 10 '13 19:06

rpearce


People also ask

Can I use media queries in SCSS?

Thanks to SCSS, you can see CSS media queries in a less intimidating light.

What does @media do in SCSS?

The important purpose of @media directive is to set style rules for various kinds of media types and could be nested inside the SASS selector.

How do you use partials in Sass?

Sass Partials scss files directly. However, when you want to import a file, you do not need the file to be transpiled directly. Sass has a mechanism for this: If you start the filename with an underscore, Sass will not transpile it. Files named this way are called partials in Sass.


1 Answers

Note the indented whitespace in the .sass file. That's the problem. Solved.

Surprising that it didn't give me any compilation errors? Maybe because it was nested within something already commented out?

like image 112
rpearce Avatar answered Nov 03 '22 21:11

rpearce