Giter VIP home page Giter VIP logo

sass-mq's Introduction

Awesome

Media Queries with superpowers Build Status

mq() is a Sass mixin that helps you compose media queries in an elegant way.

Here is a very basic example:

@use 'mq' as * with (
  $breakpoints: (
    mobile: 320px,
    tablet: 740px,
    desktop: 980px,
    wide: 1300px,
  )
);

.foo {
  @include mq($from: mobile, $until: tablet) {
    background: red;
  }
  @include mq($from: tablet) {
    background: green;
  }
}

Compiles to:

@media (min-width: 20em) and (max-width: 46.24em) {
  .foo {
    background: red;
  }
}
@media (min-width: 46.25em) {
  .foo {
    background: green;
  }
}

Sass MQ was crafted in-house at the Guardian. Today, many more companies and developers are using it in their projects: see who uses Sass MQ.

How to use it

Immediately play with it on SassMeister: @use 'mq';.

OR:

  1. Install:

    • with Bower: bower install sass-mq --save
    • with npm: npm install sass-mq --save
    • with yarn: yarn add sass-mq

    OR Download _mq.scss into your Sass project.

  2. Import the partial in your Sass files and override default settings with your own preferences:

// Name your breakpoints in a way that creates a ubiquitous language
// across team members. It will improve communication between
// stakeholders, designers, developers, and testers.
$breakpoints: (
  mobile: 320px,
  tablet: 740px,
  desktop: 980px,
  wide: 1300px,
  // Tweakpoints
  desktopAd: 810px,
  mobileLandscape: 480px,
);

// If you want to display the currently active breakpoint in the top
// right corner of your site during development, add the breakpoints
// to this list, ordered by width. For examples: (mobile, tablet, desktop).
$show-breakpoints: (mobile, mobileLandscape, tablet, desktop, wide);

@use 'path/to/mq' with (
  $breakpoints: $breakpoints,
  $show-breakpoints: $show-breakpoints
);

Notes about @use Vs @import

When using the @use directive, you have to change your mindset when working with vars, functions or mixins and how they are now seen by Sass.

Previously, with the @import statement any var, function, or mixin were exposed in the global scope. That means that you could define a var like $mq-media-type: all in your main sass file and use it anywhere as long as the main file had been loaded previously.

This was possible because vars, functions, and mixins were set in the global scope.

One drawback of this behaviour was that we needed to ensure not to pollute the global scope with common names or names that may be already taken by any other library.

To solve this matter, we mostly used a prefix in vars, functions, or mixins in order to avoid collapsing names.

Now with the new @use directive, no var, function, or mixin is placed in global scope, and they are all scoped within the file.

That means that we explicitly need to include the partial file in each file that may use its vars, functions or mixins (similar to ES6 import modules).

So, previously we could have a typical setup like this:

// main.scss
@import 'mq';
@import 'typography';
@import 'layout';
@include mq($from:tablet) {
  ...
}

...

// typography.scss
@include mq($from:tablet) {
  ...
}

Now, you will need to explicitly import the _mq.scss file in each file that needs to use any var, function or mixin from it:

// main.scss
@use 'mq';
@use 'typography';
@use 'layout';
@include mq.mq($from:tablet) {
  ...
}
...

// typography.scss
@use 'mq';
@include mq.mq($from:tablet) {
  ...
}

Other important things about @use:

  • The file is only imported once, no matter how many times you @use it in a project.

  • Variables, mixins, and functions (what Sass calls “members”) that start with an underscore (_) or hyphen (-) are considered private, and not imported.

  • Members from the used file are only made available locally, but not passed along to future imports.

  • Similarly, @extends will only apply up the chain; extending selectors in imported files, but not extending files that import this one.

  • All imported members are namespaced by default.

Please see introducing-sass-modules for more info about sass modules.

  1. Play around with mq() (see below)

Responsive mode

mq() takes up to three optional parameters:

  • $from: inclusive min-width boundary
  • $until: exclusive max-width boundary
  • $and: additional custom directives

Note that $until as a keyword is a hard limit i.e. it's breakpoint - 1.

@use 'mq';

.responsive {
  // Apply styling to mobile and upwards
  @include mq.mq($from: mobile) {
    color: red;
  }
  // Apply styling up to devices smaller than tablets (exclude tablets)
  @include mq.mq($until: tablet) {
    color: blue;
  }
  // Same thing, in landscape orientation
  @include mq.mq($until: tablet, $and: '(orientation: landscape)') {
    color: hotpink;
  }
  // Apply styling to tablets up to desktop (exclude desktop)
  @include mq.mq(tablet, desktop) {
    color: green;
  }
}

Verbose and shorthand notations

Sometimes you’ll want to be extra verbose (for example, if you’re developing a library based on top of sass-mq), however for readability in a codebase, the shorthand notation is recommended.

All of these examples output the exact same thing and are here for reference, so you can use the notation that best matches your needs:

@use 'mq';
// Verbose
@include mq.mq(
  $from: false,
  $until: desktop,
  $and: false,
  $media-type: $media-type // defaults to 'all'
) {
  .foo {
  }
}

// Omitting argument names
@include mq.mq(false, desktop, false, $media-type) {
  .foo {
  }
}

// Omitting tailing arguments
@include mq(false, desktop) {
  .foo {
  }
}

// Recommended
@include mq($until: desktop) {
  .foo {
  }
}

See the detailed API documentation

Adding custom breakpoints

@include add-breakpoint(tvscreen, 1920px);

.hide-on-tv {
  @include mq(tvscreen) {
    display: none;
  }
}

Seeing the currently active breakpoint

While developing, it can be nice to always know which breakpoint is active. To achieve this, set the $show-breakpoints variable to be a list of the breakpoints you want to debug, ordered by width. The name of the active breakpoint and its pixel and em values will then be shown in the top right corner of the viewport.

// Adapt the list to include breakpoint names from your project
$show-breakpoints: (phone, phablet, tablet);

@use 'path/to/mq' with (
  $show-breakpoints: $show-breakpoints
);

$show-breakpoints

Changing media type

If you want to specify a media type, for example to output styles for screens only, set $media-type:

SCSS

@use 'mq' with (
  $media-type: screen
);

.screen-only-element {
  @include mq.mq(mobile) {
    width: 300px;
  }
}

CSS output

@media screen and (max-width: 19.99em) {
  .screen-only-element {
    width: 300px;
  }
}

Implementing sass-mq in your project

Please see the examples folder which contains a variety of examples on how to implement "sass-mq"

Backward compatibility with @import

Just in case you need to have backward compatibility and want to use@import instead of @use, you can do so by importing _mq.import.scss instead of _mq.scss.

Please see legacy.scss on examples folder.

Running tests

npm test

Generating the documentation

Sass MQ is documented using SassDoc.

Generate the documentation locally:

sassdoc .

Generate & deploy the documentation to http://sass-mq.github.io/sass-mq/:

npm run sassdoc

Inspired By…

On Mobile-first CSS With Legacy Browser Support

Who uses Sass MQ?

Sass MQ was developed in-house at the Guardian.

These companies and projects use Sass MQ:


Looking for a more advanced sass-mq, with support for height and other niceties?
Give @mcaskill's fork of sass-mq a try.

sass-mq's People

Contributors

36degrees avatar ahmedelgabri avatar area73 avatar arekbartnik avatar bewildergeist avatar commuterjoy avatar dependabot[bot] avatar hackzzila avatar kaelig avatar kittygiraudel avatar mattandrews avatar ngryman avatar nickcolley avatar prayagverma avatar sndrs avatar steffenweber avatar txhawks avatar tzi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sass-mq's Issues

sass-mq on npm

I would be really nice to have sass-mq released on npm.

npm support

Hey @kaelig,

Have you ever thought about publishing this through npm too? I would love to avoid using bower for the sake of 1 project.

Combination with print styles ?

Hi there,

I've seen a particular case: a website in made in mobile-first, and it would need for printing output to have desktop styles applied for print.

Would it be possible to generate something like

@media (min-width: 20em), print {

with sass-mq ?

Thanks for your advice,
Nico

mq:129: expected '{' in media query

I'm getting this error when sass is compiling my css. I'm using gulp-sass, so I'm not sure who to blame :-)

Thanks in advance for any help you can give!

mq(hdpi) and height

Hello,

I use Sass-mq on several project.
I would use it for some other rules.

  • min and max height
  • hdpi

Can it be added ?

Higher breakpoints for higher resolutions

I've been making web pages lately without thinking of high resolution monitors (Quad HD, 4k, Retina, what'not). So after buying a 1440p monitor I notice my web pages also should be optimized for this resolution.

Can predefined breakpoints for higher resolutions be bundled with sass-mq in the future?

$mq-breakpoints: (
    mobile:  320px,
    tablet:  740px,
    desktop: 980px,
    wide:    1300px
)

I know I can do this myself, but thought this would be a great idea anyway. And by the way: what resolutions would you recommend for these breakpoints and a "hardcode case"?

Cheers. Love sass-mq and your contributions! 💃

"is not a map" error

Using Sass 3.4.9 (Selective Steve)

I get this error:

error css/_mq.scss (Line 110: $map: "mq-add-breakpoint(gel-bp-type-c, 600px)" is not a map for `map-has-key')

Update list using SassScript Maps ?

The new Maps data type in Sass 3.3 is awesome, I think, using it is better ;)

$mq-breakpoints: (mobile: 300px , tablet : 600px, desktop :900px, wide :1260px) !default;

@function mq-retrieve-breakpoint-width($name) {
    @each $mq-breakpoint, $breakpoint in $mq-breakpoints {
        $breakpoint-name: #{$mq-breakpoint};
        $breakpoint-width: $breakpoint;

        @if $name == $breakpoint-name {
            @return $breakpoint-width;
        }
    }
    @return 'Breakpoint #{$name} does not exist';
}

How to use media expressions

Hi! Thanks for this excellent tool. I'm wondering how I can set a map of media expressions. Something like

$media-expressions: (
  'screen': 'screen',
  'print': 'print',
  'handheld': 'handheld',
  'landscape': '(orientation: landscape)',
  'portrait': '(orientation: portrait)',
  'retina2x': '(-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi), (min-resolution: 2dppx)',
  'retina3x': '(-webkit-min-device-pixel-ratio: 3), (min-resolution: 350dpi), (min-resolution: 3dppx)'
)

Rename $until into $to

The word from is often opposed to to. In order to make the API more intuitive, what about renaming $until into $to?

Note that this may trigger an API break.

eyeglass 0.8 throws a warning with sass-mq

Hi,

Every time you run node-sass, eyeglass produces an error saying:

The following modules did not declare an eyeglass version:
  sass-mq
Please add the following to the module's package.json:
  "eyeglass": { "needs": "^0.8.2" }

After looking at the eyeglass documentation, I have created a PR #78 which adds required information to the package.json. I have also bumped the required eyeglass version because of this change.

I believe this is correct but let me know if I need to make any changes.

Compiled CSS with $until tag is not '$breakpoint - 1'

I am using your breakpoints on a project and an $until query is not taking 1 away from my breakpoint. See below:

@include mq($until: breakpoint('xl')) {
    ...
}

@include mq($from: breakpoint('xl')) {
    ...
}

Is being compiled into:

@media (max-width: 60em) {
    ...
}
@media (min-width: 60em) {
    ...
}

In this case, some styles from the $until breakpoint are being displayed during the 1px overlap at the $from breakpoint causing some issues.

Thanks,
Jay

Sort mq-breakpoints when adding breakpoint

When adding a breakpoint with the mq-add-breakpoint mixin, can the function sort the breakpoint list. This prevents libraries that loop over the mq-breakpoints from having breakpoints added later overtaking larger breakpoints.
For instance, in my code I added a phablet breakpoint. It put it on the end of the list so when inuitcss generates the width utilities the phablet one is generated later than the tablet one so it overrides it when I want different widths at the two points but only one shows up.

Split media query string logic into separate function

It would be awesome if the underlying logic could be split out into a separate function. The use case for this would be to support several breakpoints in one media query.

A possible syntax for this could be:

@media ( #{ mq-string( $from: tablet, $until: desktop ) }, #{ mq-string( $from: 1000px, $until: 1200px ) }  ) {
  ...
}

Unfortunately is seems the strings have to be interpolated to be accepted. I've played around with the syntax here: http://codepen.io/NicolajKN/pen/OVKpjL?editors=110

Problem with the syntax

Hi,
when I try to compile my scss I get this warning:
Syntax error: Invalid CSS after " mobile": expected ")", was ": 320px,"

I've Sass 3.3.8 (Maptastic Maple)

Error: media query expression must begin with '('

I'm getting this error with the latest version of node:

Error: my/path/to/_mq.scss
218:50  media query expression must begin with '('

I'm not even sure what dependency might be at fault here, so I'm sorry if I'm way off. Any ideas about why this might be occurring?

Simplify Sass syntax

Parenthesis are often optional in Sass. We could remove them to simplify the code. Any thoughts?

Parser error

Some CSS parsers will break, when using the "mq-show-breakpoints" mixin. The reason for this is the "≥" sign. I used this in a CoreMedia system which minified the css and breaked then on this part

$mq-show-breakpoints not working.

I'm using:

@include mq-add-breakpoint(xsmall, 600px);
@include mq-add-breakpoint(small, 768px);
@include mq-add-breakpoint(medium, 992px);
@include mq-add-breakpoint(large, 1024px);
@include mq-add-breakpoint(xlarge, 1200px);

$mq-show-breakpoints: (xsmall, small, medium, large, xlarge);

But no :before element is appearing on my body element in the browser (tested on FF49 and Chrome 54).

Am I using MQ right? I can see the original pull request here: #7

Stop converting media queries to em

Hi,

sass-mq currently converts all breakpoints to em values, using a ratio of 1em = 16px (that ratio can be changed but it would definitely create unexpected behavior for users, so it's a good thing the variable for that is not advertised). The rationale for converting to em was browser limitations (January 2014 post) with zooming. More specifically, it was a WebKit bug, affecting Chrome and Safari, which has since been fixed (around 2014?).

No zoom issue with px media queries in my tests on:

  • Recent and older Firefoxes
  • IE 9, IE 11
  • Chrome 30
  • Safari 8, Safari 6.1 on OS X

So it seems safe to say it's a non-issue now. What's more, using em media queries as substitutes for pixels can pose a risk if end users have changed the browser's base font size to something that is not 16px (to be confirmed; not sure if it does impact em-based media queries in all browsers).

I suggest that sass-mq stop converting pixels to ems and allow users to set breakpoints in ems in $mq-breakpoints (if that is not already the case). For max-width queries, a pixel breakpoint should be reduced by one, e.g. (max-width: 799px) if the breakpoint is 800px.

Add ability to specify predefined values for `$and`

I think it makes sense to be able to specify a media-query name in the $and parameter, rather than a string. It is a much better fit for the bridging-the-gap-between-designers-and-developers philosophy.

After all, when people want to display a different image on high density screens, they mostly think of it as 'lets show a higher resolution image on retina or hidpi', not as 'lets show a higher resolution image on (-webkit-min-device-pixel-ratio: 1.3), (min-resolution: 120dpi), (min-resolution: 1.3dppx)'.

Writing @include mq($and: hidpi) is much more reasonable than writing. @include mq($and: '(-webkit-min-device-pixel-ratio: 1.3), (min-resolution: 120dpi), (min-resolution: 1.3dppx)'), especially for designers.

The way I see it, there are three easy ways to achieve this:

  1. Simply having the mq mixin search the $mq-breakpoints map, and define the rules there.
    Downside: it makes is harder for people to loop over the $mq-breakpoints map if they want to for some reason. Looping could still be done by testing if the value of the key to be a number, but it adds another validation step. I guess this makes it a breaking change.

  2. Adding a second map, say $mq-misc-breakpoints, where miscellaneous breakpoints would be defined. If choosing this path, perhaps $mq-breakpoints should be renamed to $mq-width-breakpoints, though this should be considered a breaking change.
    Downside: Requires managing two definition maps, higher cognitive load.

  3. Splitting the the $mq-breakpoints map into two sub-maps:

    $mq-breakpoints: (
      widths: (   // maybe lengths is a better name?
        mobile: 320px,
        // etc.
      ),
      misc: (     // Maybe features?
        landscape: '(orientation: landscape)',
        // etc.
      ),
    ) !default;

    Downside: I think this is the best approach, but It's a breaking change

If you think this is a worthy change, I'll be happy to submit a pull request

Travis build is failing

Tests are running locally with success but it looks like there is an issue with the latest version of Eyeglass when running on Travis, see:
https://travis-ci.org/sass-mq/sass-mq/builds/73874507

Stacktrace:

/home/travis/build/sass-mq/sass-mq/node_modules/eyeglass/node_modules/node-sass-utils/lib/sass_js_map.js:168
  SassJsMap.prototype[Symbol.iterator] = function() {
                      ^
ReferenceError: Symbol is not defined
    at module.exports (/home/travis/build/sass-mq/sass-mq/node_modules/eyeglass/node_modules/node-sass-utils/lib/sass_js_map.js:168:23)
    at module.exports (/home/travis/build/sass-mq/sass-mq/node_modules/eyeglass/node_modules/node-sass-utils/lib/index.js:185:45)
    at module.exports (/home/travis/build/sass-mq/sass-mq/node_modules/eyeglass/lib/assets.js:206:45)
    at Object.Eyeglass (/home/travis/build/sass-mq/sass-mq/node_modules/eyeglass/lib/index.js:17:36)
    at Object.<anonymous> (/home/travis/build/sass-mq/sass-mq/test/eyeglass-test.js:11:16)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)
travis_time:end:1d428ac1:start=1438601025365766669,finish=1438601025935514225,duration=569747556

Libsass support

Hi just noticed the sass-mq doesn't compile correctly with libsass right now.

This may be more relevant for the libsass repo but the problem is the string interpolation used here

   @media all #{$mediaQuery} {
          @content;
    }

v2.2 not picked up by bower

v2.2 isn't picked up by Bower because it's not a recognised semver version number.

Can you please make a release for the v2.2.0?

Add backticks around values in warnings

It is quite a convention at this point.

For instance:

@warn "Breakpoint #{$name} wasn't found in $breakpoints.";

Following conventions, we could have:

@warn "Breakpoint `#{$name}` wasn't found in $breakpoints.";

Same here.

Remove a useless variable

Here:

@mixin mq-add-breakpoint($name, $width) {
    $new-breakpoint: ($name: $width);
    $mq-breakpoints: map-merge($mq-breakpoints, $new-breakpoint) !global;
}

Could (should?) be:

@mixin mq-add-breakpoint($name, $width) {
    $mq-breakpoints: map-merge($mq-breakpoints, ($name: $width)) !global;
}

No need to create an extra variable here.

Support IE8 with media queries

Have you considered rather than creating a separate stylesheet and detecting IE8, that you create your base styles which incorporate a fixed width and then override them with a min-width media query - which will be excluded from IE8 anyway as it's not supported?

multiple media query areas

Hi there,

Firstly, thanks for the excellent tool!

I'm having trouble trying to create multiple media query areas, when I try and use two $to functions my preprocessor fails to compile the sass. I'm attempting to do something like this:

@media all and (max-width: 400px), (min-width: 650px) and (max-width: 1200px) {
// fun stuff
}

But there doesn't seem to be any suggestions for how to write this type of thing in the README.
Any help much appreciated.

Thanks,
Josh

issue with eyeglass and npm 3

Hi,

With Node 5.1.0 & Eyeglass 0.7.1, sass-mq isn't importing as the 'sass/index.scss' file is missing when you install the package. I have made a (confirmed working) pull request to address this by adding the file to the package.json files list.

Cheers.

What future for Sass MQ?

Observations

Examples

This is how Sass MQ compares with the new up-and-coming features of Sass and Media Queries Level 4.

Sass MQ

@include mq($from: mobile, $until: tablet) { /* ... */ }

Media Queries level 4

Note: you'd use PostCSS to compile this code to standard Media Queries.

// New syntax
@media (width >= 20em) and (width < 46.24em) { /* ... */ }

// Custom Media Query - Example 1
@custom-media --from-mobile-until-tablet (width >= 20em) and (width < 46.24em);
@media (--from-mobile-until-tablet) { /* ... */ }

// Custom Media Query - Example 2
@custom-media --from-mobile (width >= 20em);
@custom-media --until-tablet (width < 46.24em);
@media (--from-mobile) and (--until-tablet) { /* ... */ }

Sass 4.0

Sass should transpiled this code to a "standard" Media Query syntax.

$mobile: 20em;
$tablet: 46.24em;
@media (width >= $mobile) and (width < $tablet) { /* ... */ }

Questions

  • What can we learn from this that could benefit Sass MQ?
  • Is Sass MQ still going to be helpful? (which brings the question: Should Sass MQ still exist?)
  • Can Sass MQ be an inspiration for the specification? What do you like in Sass MQ that you'd like to see in the spec?
  • Should Sass MQ support more media query types?
    • What would the API look like?
    • What best practices would it promote (knowing there are only very few use cases outside of 'screen width/height' in RWD right now)?
  • Should Sass MQ drop support for the non-responsive mode (mostly useful for IE8)? Note that this is achievable using postcss-unmq.

I'd love to hear your thoughts, as I'd like Sass MQ to be as relevant as possible in the future, unless it is better replaced by other tools (in which case there is no point supporting it).

How to import sass-mq in a project when installed from npm

Hi! I installed sass-mq with npm using npm install sass-mq --save and tried all the combinations then to import it in a SASS file. These are:

  • @import '_mq';
  • @import 'mq';
  • @import '_sass-mq';
  • @import 'sass-mq';
  • @import '_mq()';
  • @import 'mq()';
  • @import 'sass-mq/mq';.

Only the "full" path version @import './node_modules/sass-mq/_mq'; has worked. Still, is there a standard alias that we can use?

Active breakpoint in a global variable.

Hey,

This is just an idea, I wanted to ask you if this makes sense.
I would like to be able to know which active breakpoint I'm writing code for. This would allow me to make decisions based on it (out of this ticket scope).

The basic idea would be to declare a global variable with the default breakpoint as initial value. The default value may depend on the approach used (mobile first, desktop first). So it should be a configurable variable:

$mq-default-breakpoint: mobile !default;
$mq-active-breakpoint: $mq-default-breakpoint;

This variable would change when calling mq(). It would be set to the active breakpoint just before the @content and then reset to its default value. Roughly something like that:

$mq-active-breakpoint: $until; // or $from? or more complex?
@content;
$mq-active-breakpoint: $mq-default-breakpoint;

The code executed in @content would then be aware of its responsive context, which could be pretty powerful.

The problem here is to define the meaning of the active breakpoint. In a mobile first approach, it would probably be the value of $from, in a desktop first approach it would probably be $until.
What happens if we specify both? Perhaps we could define a direction.

But first, does this makes sense to you? :neckbeard:

Media query "void" when text zoom is on

Media queries are calculated on a 16px baseline, which means that if this baseline changes, media queries do too.

Original media query

In the case of set of media queries like:

@media (max-width: 61.1875em) { /* styles */ }
@media (min-width: 61.25em)   { /* styles */ }

16 px baseline (default)

With a baseline of 16px, it gets translated into:

@media (max-width: 979px) { /* styles */ }
@media (min-width: 980px)   { /* styles */ }

Which is fine.

20px baseline

screen shot 2013-11-04 at 18 51 34

With text zoom enabled (here, "medium" text size in Chrome), we end up with:

@media (max-width: 1223.75px) { /* styles */ }
@media (min-width: 1225px)   { /* styles */ }

We created a 1 pixel gap where no styles apply, leading to the following type of issues:

screen shot 2013-11-04 at 18 44 23

Fix

We set the gap to 0.01em to reduce the risk of style voids between breakpoints as suggested by @tzi.

/Thanks to @ryuran and @tzi for flagging this.

Also read @tzi's article on the double breakpoint problem, closely related to this rounding and scaling issue: http://tzi.fr/css/double-breakpoint-bug

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.