All Projects → pierreburel → Sass Rem

pierreburel / Sass Rem

Licence: mit
Sass function and mixin to use rem units with optional pixel fallback.

Labels

Projects that are alternatives of or similar to Sass Rem

Node Sass Magic Importer
Custom node-sass importer for selector specific imports, module importing, globbing support and importing files only once.
Stars: ✭ 273 (-12.22%)
Mutual labels:  sass
React Redux Sass Starter
Everything you need to get started with a basic React application
Stars: ✭ 293 (-5.79%)
Mutual labels:  sass
Oruga
🐛 Oruga is a lightweight library of UI components without CSS framework dependency
Stars: ✭ 297 (-4.5%)
Mutual labels:  sass
Almace Scaffolding
AMSF, a.k.a. Almace Scaffolding, a super-fast Jekyll framework fighting against the website obesity.
Stars: ✭ 275 (-11.58%)
Mutual labels:  sass
Vue Zhihu Daily
🤓使用vue编写的练手的知乎日报WebApp(iOS版)
Stars: ✭ 285 (-8.36%)
Mutual labels:  sass
Scally
Scally is a Sass-based, BEM, OOCSS, responsive-ready, CSS framework that provides you with a solid foundation for building reusable UI's quickly 🕶
Stars: ✭ 294 (-5.47%)
Mutual labels:  sass
Threejs Webpack Es6 Boilerplate
A basic boilerplate for a Three.js project compiled with Webpack and transpiled via Babel to enable using ES6 syntax.
Stars: ✭ 267 (-14.15%)
Mutual labels:  sass
Scssphp
SCSS compiler written in PHP
Stars: ✭ 309 (-0.64%)
Mutual labels:  sass
Air Light
WordPress starter theme - designed to be minimal, lightweight and easy for all kinds of WordPress projects. Public Roadmap: https://favro.com/organization/3b45e73eaf083f68fefef368/c1dd2d4a99d6723904d2e763
Stars: ✭ 285 (-8.36%)
Mutual labels:  sass
Styled Components Theme
Defines themes via flexible color selectors for use with styled-components
Stars: ✭ 302 (-2.89%)
Mutual labels:  sass
Mini.css
A minimal, responsive, style-agnostic CSS framework!
Stars: ✭ 2,938 (+844.69%)
Mutual labels:  sass
Vortex React
🐠 A react starter kit. Redux or mobx, react-router-dom, webpack3, all is in.
Stars: ✭ 282 (-9.32%)
Mutual labels:  sass
Playstationdiscord
Discord Rich Presence for PlayStation 4, PlayStation 3, and PlayStation Vita games.
Stars: ✭ 291 (-6.43%)
Mutual labels:  sass
Juice
Mixins for Life
Stars: ✭ 274 (-11.9%)
Mutual labels:  sass
React Redux Chat
🔥🔥react+redux-chat 模仿实现PC微信聊天系统。
Stars: ✭ 308 (-0.96%)
Mutual labels:  sass
Input Range Scss
Styling Cross-Browser Compatible Range Inputs with Sass
Stars: ✭ 272 (-12.54%)
Mutual labels:  sass
Jeet
The most advanced, yet intuitive, grid system available for Sass or Stylus
Stars: ✭ 3,015 (+869.45%)
Mutual labels:  sass
Simple Typography
A simple starting ground for beautiful typography on the web using Sass.
Stars: ✭ 311 (+0%)
Mutual labels:  sass
Kratos Boilerplate
🔥 A simple boilerplate for creating statics PWA using Webpack, Pug, PostCSS and CSS Modules
Stars: ✭ 308 (-0.96%)
Mutual labels:  sass
Hstardoc
My blogs write with markdown.
Stars: ✭ 297 (-4.5%)
Mutual labels:  sass

Rem

Sass function and mixin to use rem units with optional pixel fallback.

Breaking change in 2.0: $rem-fallback is now set to false (see support) and $rem-baseline to 16px by default.

Demo: Sassmeister / Codepen

Compatibility: Sass 3.2+ (3.3+ for maps) and LibSass.

PostCSS version: https://github.com/pierreburel/postcss-rem

See also: https://github.com/pierreburel/sass-em


Installation

Download _rem.scss or install with Yarn, npm or Bower:

  • yarn add sass-rem
  • npm install sass-rem --save
  • bower install sass-rem --save

Then, import _rem.scss depending of your configuration and file structure.

Examples
  • @import "~sass-rem"; with sass-loader or node-sass-package-importer (recommended)
  • @import "sass-rem/rem"; when using node-sass’ includePaths to resolve node_modules or bower_components dirs
  • @import "../../node_modules/sass-rem/rem"; if none of the above and working in something like ./src/scss/main.scss
  • @import "../../bower_components/sass-rem/rem"; if using Bower
  • @import "lib/rem"; if manually copied _rem.scss in a lib folder, for example

Usage

SCSS

.demo {
  font-size: rem(24px); // Simple
  padding: rem(5px 10px); // Multiple values
  border-bottom: rem(1px solid black); // Multiple mixed values
  box-shadow: rem(0 0 2px #ccc, inset 0 0 5px #eee); // Comma-separated values
  text-shadow: rem(1px 1px) #eee, rem(-1px) 0 #eee; // Alternate use
}

CSS

.demo {
  font-size: 1.5rem;
  padding: 0.3125rem 0.625rem;
  border-bottom: 0.0625rem solid black;
  box-shadow: 0 0 0.125rem #ccc, inset 0 0 0.3125rem #eee;
  text-shadow: 0.0625rem 0.0625rem #eee, -0.0625rem 0 #eee;
}

Using pixel fallback

You can enable pixel fallback by setting $rem-fallback to true, but you will have to use the mixin instead of the function.

SCSS

$rem-fallback: true;

.demo {
  @include rem(font-size, 24px); // Simple
  @include rem(padding, 5px 10px); // Multiple values
  @include rem(border-bottom, 1px solid black); // Multiple mixed values
  @include rem(box-shadow, 0 0 2px #ccc, inset 0 0 5px #eee); // Comma-separated values
  // Multiple properties
  @include rem((
    margin: 10px 5px,
    text-shadow: (1px 1px #eee, -1px -1px #eee) // Parentheses needed because of comma
  ));
}

CSS

.demo {
  font-size: 24px;
  font-size: 1.5rem;
  padding: 5px 10px;
  padding: 0.3125rem 0.625rem;
  border-bottom: 1px solid black;
  border-bottom: 0.0625rem solid black;
  box-shadow: 0 0 2px #ccc, inset 0 0 5px #eee;
  box-shadow: 0 0 0.125rem #ccc, inset 0 0 0.3125rem #eee;
  margin: 10px 5px;
  margin: 0.625rem 0.3125rem;
  text-shadow: 1px 1px #eee, -1px -1px #eee;
  text-shadow: 0.0625rem 0.0625rem #eee, -0.0625rem -0.0625rem #eee;
}

You can totally disable rem units by setting $rem-px-only to true (for a lt-ie9 only stylesheet for example).

CSS

.demo {
  font-size: 24px;
  padding: 5px 10px;
  border-bottom: 1px solid black;
  box-shadow: 0 0 2px #ccc, inset 0 0 5px #eee;
  margin: 10px;
  text-shadow: 1px 1px #eee, -1px -1px #eee;
}

Changing baseline

By default, sass-rem now uses a 16px baseline, but you can change this value with $rem-baseline and by using the rem-baseline mixin on the html element to adjust the root font size. The rem function and mixin will calculate rem values accordingly. For example, you can set $rem-baseline to 10px to have a root font size of 62.5% and improve readability (10px = 1rem), which was the pre-2.0 behavior.

SCSS

$rem-baseline: 10px;

html {
  @include rem-baseline;
}

.demo {
  font-size: rem(24px);
}

CSS

html {
  font-size: 62.5%;
}

.demo {
  font-size: 2.4rem;
}

You can also change the baseline zoom by passing the desired zoom to the rem-baseline mixin which will calculate it depending of $rem-baseline. Useful for creating responsive typography depending on viewport, especially with a different baseline than 16px.

SCSS

$rem-baseline: 10px;

html {
  @include rem-baseline; // Default zoom to 100%

  @media (max-width: 400px) {
    @include rem-baseline(75%);
  }

  @media (min-width: 800px) {
    @include rem-baseline(125%);
  }
}

CSS

html {
  font-size: 62.5%;
}

@media (max-width: 400px) {
  html {
    font-size: 46.875%;
  }
}

@media (min-width: 800px) {
  html {
    font-size: 78.125%;
  }
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].