Skip to content

Instantly share code, notes, and snippets.

@amlang
Last active June 3, 2018 14:10
Show Gist options
  • Save amlang/c82496a3b36050616e99963d23c5d291 to your computer and use it in GitHub Desktop.
Save amlang/c82496a3b36050616e99963d23c5d291 to your computer and use it in GitHub Desktop.
Material-Design Typography scss
<html lang="en" dir="ltr">
<head>
<title>Mat-Typo</title>
<meta key="viewport" name="viewport" content="initial-scale=1.0, width=device-width, shrink-to-fit=no" />
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,500" />
<link rel="stylesheet" href="./styles.css" />
</head>
<body>
<p class='mat-h4'> Material Design - Typography example</p>
<p class="mat-body1"> More information can be found in the documentation under
<a href="https://material.io/design/typography/#type-scale">
Material Design / Typography / Type Scale
</a>.
</p>
<p class='mat-h1'>H1 Light 96sp</p>
<p class='mat-h2'>H2 Light 60sp</p>
<p class='mat-h3'>H3 Regular 48sp</p>
<p class='mat-h4'>H4 Regular 34sp</p>
<p class='mat-h5'>H5 Regular 24sp</p>
<p class='mat-h6'>H6 Medium 20sp</p>
<p class='mat-subtitle1'>Subtitle1 Regular 16sp</p>
<p class='mat-subtitle2'>Subtitle1 Medium 14sp</p>
<p class='mat-body1'>Body1 Regular 16sp</p>
<p class='mat-body2'>Body2 Regular 14sp</p>
<p class='mat-button'>BUTTON Medium 14sp</p>
<p class='mat-caption'>Caption Regular 12sp</p>
<p class='mat-overline'>OVERLINE Medium 10sp</p>
</body>
</html>
/* Load google's Roboto font*/
/* More information can be found here */
/* @see https://material.io/design/typography/#type-scale*/
/* @see https://gist.github.com/amlang/c82496a3b36050616e99963d23c5d291 */
/* @see https://material.io/ */
/* @see https://github.com/material-components/material-components-web/blob/master/LICENSE */
@import url(https://fonts.googleapis.com/css?family=Roboto:300,400,500,900);
/* Reboot */
html, body { margin: 0 !important; }
/* Typography */
body {
font-family: "Roboto", 'Helvetica Neue, Helvetica, Arial';
}
/*Convertion Ration sp to rem for html */
$conversionRatioSpToRemWeb: 1/16; //! 0.0625;
$conversionRatioRemToPxWeb: 16.0;
/*functions*/
/* Scaled-Points to root em */
/* $sps {number} scaled points to convert */
/* @returns {number} 1/16th of $sps */
@function spToRem($sps){
@return $sps * $conversionRatioSpToRemWeb;
};
/* root em to Pixel */
/* $rems {number} root ems to convert */
/* @returns {number} the 16 times of $rems */
@function remToPx($rems){
@return $rems * $conversionRatioRemToPxWeb;
};
/* spacing */
/* @returns {number} the division of tracking and px */
@function spacing($tracking, $px){
@return $tracking / $px;
};
/*Mixins*/
@mixin mat-typo($size, $weight, $spacing) {
font-weight: $weight;
font-size: #{spToRem($size)}rem;
letter-spacing: #{spacing($spacing, remToPx($size))}px;
}
// Weights
$font-weight-thin: 100;
$font-weight-light: 300;
$font-weight-regular: 400;
$font-weight-medium: 500;
$font-weight-bold: 700;
$font-weight-black: 900;
/* Headers */
.mat-h1, .h1 { @include mat-typo(96, $font-weight-light, -1.5); }
.mat-h2, .h2 { @include mat-typo(60, $font-weight-light, -.5); }
.mat-h3, .h3 { @include mat-typo(48, $font-weight-regular, 0); }
.mat-h4, .h4 { @include mat-typo(34, $font-weight-regular, .25); }
.mat-h5, .h5 { @include mat-typo(24, $font-weight-regular, 0); }
.mat-h6, .h6 { @include mat-typo(20, $font-weight-medium, .15); }
.mat-subtitle1 { @include mat-typo(16, $font-weight-regular, .15); }
.mat-subtitle2 { @include mat-typo(14, $font-weight-medium, .1); }
.mat-body1 { @include mat-typo(16, $font-weight-regular, .5); }
.mat-body2 { @include mat-typo(14, $font-weight-regular, .25); }
.mat-button {
@include mat-typo(14, $font-weight-medium, .75);
text-transform: uppercase;
}
.mat-caption { @include mat-typo(12, $font-weight-regular, .4); }
.mat-overline {
@include mat-typo(10, $font-weight-regular, 1.5);
text-transform: uppercase;
}
@amlang
Copy link
Author

amlang commented Jun 2, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment