Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

🎨 Deal with responsive design simply when use CSS-in-JS (styled-components,emotion.js)

License

NotificationsYou must be signed in to change notification settings

Brew-Brew/css-in-js-media

Repository files navigation

Minified and Simplified include-media with CSS-in-JS

when you style with css-in-js (emotion, styled-component) you can perfectly and easily deal with responsive design with thiscss-in-js-media which is similar withinclude-media and support type system(ts)

If you think this library is helpful, Support by give ⭐

Migrate to Typescript at version V2 🎉

Introduced at


📖 documentation


🚀 install & default usage

npm install css-in-js-mediaimport media from "css-in-js-media";

media-query break-point (default breakpoint)

smallPhone: 320phone: 375tablet: 768desktop: 1024largeDesktop: 1440

🎒 size

image


❓ how-to-use

with css-in-js library (ex: emotion.js , styled-component)

  • example withemotion.js
importmediafrom"css-in-js-media";exportconstexampleClass=css`color: red;${media(">desktop")} {font-size:15px;  }${media("<=desktop",">tablet")} {font-size:20px;  }${media("<=tablet",">phone")} {font-size:25px;  }${media("<=phone")} {font-size:30px;  }`;
  • example withstyled-component
importmediafrom"css-in-js-media";constexampleClass=styled.h1`  color: red;${media(">desktop")} {    font-size: 15px;  }${media("<=desktop",">tablet")} {    font-size: 20px;  }${media("<=tablet",">phone")} {    font-size: 25px;  }${media("<=phone")} {    font-size: 30px;  }`;

set flexible breakpoints (optional)

⚠️ You should set this in entry point file (root file)

import{setBreakPoints}from"css-in-js-media";setBreakPoints({desktop:1440,largeDesktop:1500});// or string sizesetBreakPoints({desktop:"140rem",largeDesktop:"calc(30 * 50px)"});

get breakpoints (optional)

import{getBreakPoints}from"css-in-js-media";getBreakPoints();// default breakpoints// {//   smallPhone: 320;//   phone: 375;//   tablet: 768;//   desktop: 1024;//   largeDesktop: 1440;// }

❤️ THANKS

🐛 Bug reporting

Issue

License

MIT


[8]ページ先頭

©2009-2025 Movatter.jp