cssresponsive-designsassbreakpoint-sasssusy-sass

susy 2.0 change columns at breakpoint


  1. I'm not using Compass
  2. I prefer to use Breakpoint.scss
  3. I'm on susy 2.0

I know there are lot of posts with this question but I'm having 0 luck finding any regarding Breakpoint.scss and Susy 2.0 on this topic.

@import "susy";
@import "breakpoint";

$medium: 800px;

$susy: (
  columns: 6,
  gutters: 3/4,
  gutter-position: split
);

@include breakpoint($medium) {
  $susy: layout(12 1/4 split);
}

body {
  @include container(show);

  @include breakpoint($medium) {
    @include container(show);
  }
}

Do I have to use susy-breakpoint or can something like this be achieved? I want 6 columns at anything at/below 800px and 12 at/above 800px

I'm trying to stay DRY so adding a susy-breakpoint in my styles does not help.

I've also tried below code but I think I just have an error somewhere cause it's not working.

$susy: layout(6 1/4 split);

$small: 400px, 6 1/4 split;
$medium: 800px, 8 1/4 split;
$large: 1000px, 12 1/4 split;

@mixin media($size) {
  @include susy-breakpoint($size...) {
    @content;
  }
}

body {
  @include container(show);

  @include media($small) {
    @include container(show);
  }

  // debugging. didnt work either
  @include susy-breakpoint($small...) {
    @include container(show);
  }
}

Solution

  • I don't know what your media mixin does, so I can't really comment on anything related to that. Your initial example doesn't work because Sass, CSS, and therefor Susy, are not aware of the DOM - or relationships between media-queries. When you change the value of $susy inside one media-query, that does not propagate to all similar media-query contexts. Because of that, you do have to set both the media-query and the desired layout every time you want a breakpoint to change the layout context.

    susy-breakpoint is not the only way to do that, but it is the shortest. Here's the longhand:

    body {
      @include container(show);
    
      @include breakpoint(800px) {
        @include with-layout(8) { // default is set to 8-columns
          @include container(show);
        } // default is returned to global setting
      }
    }
    

    Your $small breakpoint currently doesn't change anything, because it is identical to your default layout. The larger ones will change the layout context for nested code — though you can simplify: Since `1/4 split' gutters aren't changing at all, they don't need to be re-stated at every breakpoint.

    $susy: layout(6 1/4 split);
    $medium: 800px, 8;
    
    body {
      @include container(show);
    
      @include susy-breakpoint($medium...) {
        @include container(show);
      }
    }
    

    That will be identical to the longhand above.