• Stars
    star
    384
  • Rank 108,135 (Top 3 %)
  • Language SCSS
  • License
    MIT License
  • Created about 9 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Breakpoints with Maps in Sass

Mappy Breakpoints, A Breakpoint Mixin that uses Sass Maps

Mappy Breakpoints is a breakpoint mixin I have hacked together to streamline web development when using a Sass map to hold the breakpoint plugin. Here's why I made this mixin

Here's a quick example. Say you have a breakpoints map and you want to grab do a min-width query for small and max-width query for large.

$breakpoints: (
  'small': 320px,
  'large': 920px
);

@include mappy-bp(small large) {
  // stuff here
}

This will automatically create a media query plus convert it into em at the same time. It will also minus off 1px from the max-width query to ensure that your breakpoints don't overlap each other.

/* output */
@media all and (min-width: 20em) and (max-width: 57.4375em) {
  // stuff
}

Installation

You can also install mappy-breakpoints via npm.

npm install mappy-breakpoints --save

Alternatively, you can download this mixin add import it directly into your stylesheet.

Usage

Mappy-breakpoints (Mixin)

Mappy-breakpoints takes in 4 arguments. Only the first one is mandatory. The rest are optional and come with some defaults.

@import mappy-bp(<$queries>, [<$type>, <$query-fallback>, <$breakpoints>]) {
  // stuff here
}

Most of the time you'll only be working with the $queries argument. Take a look at the queries section for more info.

Mappy-query(Mixin)

mappy-query is a mixin that allows you to use any mappy-bp query repeatedly across your site. It requires you to have a $mappy-queries map.

This $mappy-queries map can contain any valid mappy-bp values, even if you use identifiers from the breakpoints map.

$breakpoints: (
  small: 480px,
  large: 800px
)

// You can use and valid arguments inserted into mappy-bp as the map values. Any of the following would do
$mappy-queries: (
  phone: mappy-bp(h max-height small), // media all and (max-height: 29.9375em)
  tablet: mappy-bp(small large), // @media all and (min-width 30em) and (max-width: 49.375em)
  desktop: mappy-bp(960px 1200px), // media all and (min-width: 60em) and (max-width: 74.9375em)
  change-type: mappy-bp(small, $type: screen) // media screen and (min-width: 30em)
)

Once you have the query stored in the $mappy-queries map, you can use it anywhere with the mappy-query mixin.

@include mappy-query(tablet) {
  // stuff
}
/* output */
@media all and (min-width: 30em) and (max-width: 49.9375em) {
  // stuff
}

Queries

Mappy-breakpoints focuses on three types of queries.

  1. width queries (min-width and max-width)
  2. height queries (min-height and max-height)
  3. The rest.

Width Queries

Width queries are the most common type of queries. You can call for width queries by simply entering the map key or the breakpoint.

Mappy breakpoints will also automatically convert the queries into the em.

If only one value is provided, mappy-breakpoints will produce a min-width query.

// Min Width Query
// ---------------
@include mappy-bp(small) {
  // stuff
}

// Translates into
@media all and (min-width: 20em) {
  // stuff
}

If a two values are provided, mappy-breakpoints will produce a min-width and max-width query.

// Min Width And Max Width Query
// -----------------------------
@include mappy-bp(small 920px) {
  // stuff
}

// Translates into
@media all and (min-width: 20em) and (max-width: 57.4375em) {
  //stuff
}

If a max-width or max string is provided, mappy-breakpoints() will produce a max-width query.

// Max Width Query
// ---------------

// You can also use `max` instead of `max-width`
@include mappy-bp(max-width 320px) {
  // stuff
}

// Translates into
@media all and (max-width: 19.9375em) {
  // stuff
}

Height Queries

Height queries in Mappy Breakpoints are set up with the h or height string. The following two arguments will be exactly the same as width queries. The only difference is that they output min-height and max-height.

It can use the same $breakpoints map as well.

// Min Height Query
// ---------------
@include mappy-bp(h small) {
  // stuff
}

// Translates into
@media all and (min-height: 20em) {
  // stuff
}

// Min Height And Max Height Query
// -----------------------------
@include mappy-bp(h small 920px) {
  // stuff
}

// Translates into
@media all and (min-height: 20em) and (max-height: 57.4375em) {
  //stuff
}

If a max-height or max string is provided, mappy-breakpoints() will produce a max-height query.

// Max Height Query
// ---------------

// You can also use `max` instead of `max-height`
@include mappy-bp(max-height 320px) {
  // stuff
}

// Translates into
@media all and (max-height: 19.9375em) {
  // stuff
}

Other Queries

Other queries can be written in a key value format, without the parenthesis or colon.

@include mappy-bp(orientation portrait) {
  // stuff
}

// Translates into
@media all and (orientation: portrait) {
  // stuff
}

Using All 3 Types of queries together

All 3 types of queries can be combined to form one complex query. Write it in order as follows:

  1. Width Queries
  2. Height Queries
  3. Other (key value) queries
@include mappy-bp(small large h 320px 920px orientation portrait) {
  // stuff
}

// Translates into
@media all and (min-width: 20em) and (max-width: 57.4375em) and (min-height: 20em) and (max-height: 57.4375em) and (orientation: portrait) {
  // stuff
}

Optional Arguments

$type determines media-type. Any valid string can be used here. If type is set to print, then mappy-breakpoints will produce a print query.

@media print and.. {
  // stuff
}

$query-fallback provides an extra class for any browsers that do not support media queries (IE 8 I'm looking at you). Since most browsers support media queries now, this shouldn't be too much of a problem, but is still here incase someone needs it.

if $query-fallback is set to the 'ie8 string, then mappy breakpoints create produce an .ie8 class for the query.

.ie8 .selector {
  // stuff
}

Finally, $breakpoints determines which map to use for the width and height queries. It defaults to $breakpoints.

More Repositories

1

typi

A sass mixin to make responsive typography easy
CSS
860
star
2

gulp-starter-csstricks

Gulp starter for CSS Tricks article
JavaScript
393
star
3

zellwk.com

Github repo for https://zellwk.com
MDX
348
star
4

zl-fetch

A library that makes the Fetch API a breeze
JavaScript
276
star
5

crud-express-mongo

Repo for Zell's CRUD, Express and Mongo tutorial
JavaScript
176
star
6

dotfiles

Shell
170
star
7

crud-demo

Source code for "Building a CRUD app with Node, Express, and MongoDB tutorial"
JavaScript
165
star
8

javascript

A collection of useful JavaScript snippets curated by Zell
JavaScript
159
star
9

css-reset

Zell's personal CSS Reset
CSS
149
star
10

adaptive-placeholders

Float label pattern built with pure SCSS
CSS
129
star
11

endpoint-testing-example

JavaScript
47
star
12

gulp-susy-starter

Susy Starter that uses LibSass with Gulp
CSS
39
star
13

themify

Sass Mixin to create multiple themes easily
CSS
34
star
14

vertical-rhythms-without-compass

CSS
18
star
15

ama

A repository where you can ask anything and Zell will answer.
9
star
16

source-for-automating-workflow-book

JavaScript
9
star
17

build-and-deploy-workshop

Astro
9
star
18

grunt-susy-starter

Susy Starter that uses LibSass with Grunt
CSS
8
star
19

devfest

github repo for the devfest.asia 2015
JavaScript
7
star
20

Learnjavascript-api

API for Learn JavaScript
JavaScript
6
star
21

convertkit-cli

A Simple CLI for Convertkit
JavaScript
6
star
22

CSSConf.Asia-animating-svg

JavaScript
6
star
23

demos

JavaScript
5
star
24

responsive-typography-slides

JavaScript
5
star
25

responsive-css-components-slides

JavaScript
5
star
26

devfest-2016

CSS
4
star
27

webpack-starter

Webpack starter (without React)
JavaScript
4
star
28

better-share-buttons

CSS
4
star
29

buffalo

Simple Blog site generator
JavaScript
4
star
30

Learning-Susy

The walkthrough codes for Learning Susy
CSS
3
star
31

simple-workflow

HTML
3
star
32

responsive-typography-workshop

CSS
3
star
33

FEWD

HTML
3
star
34

basic-susy-starter

A very simple Susy Starter that uses the terminal to compile Sass into CSS
CSS
3
star
35

learngit.io

Website for learngit.io
HTML
3
star
36

ava-mdb-test

JavaScript
2
star
37

Dojo-Playground

Astro
2
star
38

countdown

A simple countdown timer to a specific date (with timezone support)
JavaScript
2
star
39

shuffle-and-split

Shuffles and splits and array into equal groups
JavaScript
2
star
40

chatapp-polymer

Chatapp built with Polymer
HTML
2
star
41

simple-susy-starter

For easy Susy related layouts / tests
CSS
2
star
42

susy-helpers

Helpers for Susy
CSS
2
star
43

scalable-components

JavaScript
2
star
44

publishing-to-npm

An example repository to teach people how to publish to npm
2
star
45

resize-images

Resizes images. Suitable for use directly in Node, or with a Gulp workflow
JavaScript
2
star
46

build-and-deploy-workshop-sanity

JavaScript
1
star
47

ayw

Website for AYW
Nunjucks
1
star
48

roam-css

CSS
1
star
49

cssnano-issue

JavaScript
1
star
50

devops

1
star
51

slides-scaling-components-cn

Slides for CSSConf China #4
JavaScript
1
star
52

compass-susy-starter

A very simple Susy Starter that uses Compass to compile Sass into CSS
CSS
1
star
53

jsroadmap.com

SCSS
1
star
54

zellwk-pdf-maker

Helps to make PDFs for https://zellwk.com
JavaScript
1
star
55

github-actions-tutorial

1
star
56

count-to-date

A simple countdown timer to a specific date
JavaScript
1
star
57

cohort19x

CSS
1
star
58

window-sizer

Small helper to make debugging responsive websites easier
JavaScript
1
star