Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums CSS Simplify Sass include (uses sass maps) possible? Reply To: Simplify Sass include (uses sass maps) possible?

#237011
Ilan Firsov
Participant

I tried my hand with it. Note that I am pretty new to SASS so maybe it’s not the best way to do this. In any case it seems to do the job.

@mixin respond-at($name) {
  $index: index(map_keys($breakpoints), $name);

  @if map-has-key($breakpoints, $name) {
    @if $index == length($breakpoints) {
      @media only screen and (min-width: map-get($breakpoints, $name)) {
        @content;
      }
    } @else {
      @media only screen and (min-width: map-get($breakpoints, $name)) and (max-width: nth(map_values($breakpoints), ( $index + 1 ))) {
        @content;
      }
    }
  }
}