See more and read the docs on the website.
A nifty Compass plugin for quick and precise typesetting without hours of math churning.
Type Up gives you the CSS rules for beautiful vertical rhythm (line-heights, paddings, margins) based on font size and line length. Customize the details as you please or use the defaults.
- Line height is based on both font size and line length for optimized readability at all measures
- Everything is in
em
s - Modular scale for heading sizes
- Headings work with half a baseline as needed
Get started with the defaults:
@include typeup-body(
1em, /* font size */
35em /* line length */
1 /* x-height ratio */
);
// Your container element for text
.text-wrapper {
width: 35em;
}
- Install the gem with
gem install typeup
- Require TypeUp in your config.rb with
require "typeup"
- Import TypeUp in your stylesheet with
@import "typeup";
- Apply styles to body with
@include typeup-body($fontSize, $lineLength, $xHeight)
or to a container with@include typeup-container($fontSize, $lineLength, $xHeight)
- Cool typesetting, bro!
Declare settings before importing typeup!
$h1LinesBefore: 2;
@import "typeup";
or, make a settings file:
@import "mytypeupsettings";
@import "typeup";
Variable | Default | Description |
---|---|---|
$fontSize | 1em | The size of your font in ems or pixels. Pixels will be converted to ems inside Type Up. |
$lineLength | 35em | The width of your text, in ems or pixels. Pixels will be converted to ems inside Type Up. |
$xHeight | 1 | Use this to adjust the global line height (for example with fonts with very short or tall x-heights). |
$ratio | fourth() | The ratio for modular scale. Can be set as a number, such as 11/10. |
$headingLinesBefore | 1 | Multiplier for heading spacing above it. The value to be multiplied is the calculated line height of the heading. |
$headingLinesAfter | 0 |
Multiplier for heading spacing below it. The value to be multiplied is the calculated line height of the heading.
|
@include typeup-body($fontSize, $lineLength, $xHeight);
The typeup-body mixin should be included by itself, not under any selector.
@include typeup-container($fontSize, $lineLength, $xHeight);
The typeup-container mixin should be used when you want the rules to apply only under a specific element. It should be included inside a selector. This mixin also establishes the width of the element with $lineLength.
@include typeup-spacer(
$size-in-ems,
$before: $headingLinesBefore, // uses default value if not supplied
$after: $headingLinesAfter, // uses default value if not supplied
$baselineShift: $headingBaselineShift, // optional
$overrideSpacingWithBaseline: $overrideSpacingWithBaseline // uses default value if not supplied
);
The spacer mixin is used to give vertical rhythm to headings inside TypeUp, but you can use it for other things.
This is how it works:
- See how many baselines are needed to meet $size-in-ems, in half increments
- Multiply by the global line height, pixel snap it
- Multiply that number with
before
to getmargin-top
andafter
to getmargin-bottom
- Apply baseline shift if larger than 0 em with
position:relative
andtop
If $overrideSpacingWithBaseline
is true (default is false), the before
and after
values are multiplied by the global line height instead of the calculated one.
You could use the mixin to make simple paragraphs: @include typeup-spacer($fontSize, 0, 1, 0, false);
which would apply a line-height and some margin to the bottom. Or any other element where you have a differing font size - line height will be adjusted correctly.
- Not tested on older browsers
Type Up is created by Tommi Kaikkonen.
Copyright 2013 Tommi Kaikkonen. Released under MIT License.