Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
7
Help us understand the problem. What is going on with this article?
@NagataNorio

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としています

7
Help us understand the problem. What is going on with this article?
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
NagataNorio
六本木の会社でWeb / App のUI系をやってます。

Comments

No comments
Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account Login
7
Help us understand the problem. What is going on with this article?