Susy: change the number of columns according to screen size

前端 未结 1 2001
遥遥无期
遥遥无期 2021-01-16 01:20

In the Compass/Sass plugin, Susy, you set the number of columns in the _base.scss file.

For a desktop view, I like to have 12 columns. However, this is too many col

相关标签:
1条回答
  • 2021-01-16 01:44

    UPDATE: Susy 1.0 now has this feature built in using the at-breakpoint mixin. See the docs on the official site.

    Yes you can! I'm in the process of baking this feature into the core of Susy, but for the time being you have to do it yourself. Here's my approach (requires the latest Compass, and Sass alpha):

    // for mobile layouts
    $total-cols: 4;
    
    .container {
      @include container;
    }
    
    // for desktops
    @media all and (min-width: 30em) {
      $total-cols: 12;
    
      .container {
        @include container;
      }
    }
    

    Repeat as needed for each break point. You can also create simple mixins to help you:

    @mixin desktop() {
      @media all and (min-width: 30em) {
        $current-total: $total-cols; // remember current column setting
        $total-cols: 12;             // change column setting for new context
    
        @content;                    // apply content with new column-count
    
        $total-cols: $current-total; // return original column setting
      }
    }
    
    .container {
      @include container;
    
      @include desktop {
        @include container;
      }
    }
    
    0 讨论(0)
提交回复
热议问题