Help us understand the problem. What is going on with this article?

Media Queriesをemで分岐させるMixin

More than 3 years have passed since last update.

pxベースでの分岐は限界

Media Queriesの分岐といえばpxベースがポピュラーですが、
2K/4K,iPhone4/5/6/plus,iPad mini/Air/Pro,Android 以下略と、
カオスな状態になりそれぞれ指定するのが手間すぎるため、
pxベースでの指定は限界な気がします。

そこで、emで分岐するMixinをオススメします。

Sass

@mixin breakpoint($point) {
   @if $point == desktop {
        @media (min-width: 90.063em) { @content ; }
    }
    @else if $point == laptop {
        @media (min-width: 64.063em) and (max-width: 90em) { @content ; }
    }
    @else if $point == tablet {
        @media (min-width: 40.063em) and (max-width: 64em) { @content ; }
    }
    @else if $point == mobileonly {
        @media (max-width: 40em)  { @content ; }
    }
}

CSS

div{
    @include breakpoint(mobileonly) {
        margin: 8px;
    }
    @include breakpoint(tablet) {
        margin: 16px;
    }
    @include breakpoint(laptop) {
        margin: 24px;
    }
    @include breakpoint(desktop) {
        margin: 32px;
    }
}

laptopはWXGAデバイスで適応されます。

2016/06/30 追記
ベースのフォントサイズを16pxとしています

NagataNorio
六本木の会社でWeb / App のUI系をやってます。
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした