• Stars
    star
    713
  • Rank 63,511 (Top 2 %)
  • Language
    CSS
  • License
    Other
  • Created almost 11 years ago
  • Updated almost 11 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A small Sass library for setting type on the web.

Typecsset (v0.3.0)

Typecsset (type·set, /ˈtīpˌset/) is a small Sass library for setting type on the web.

It gives you an automatic, pixel-perfect, baseline grid across all textual HTML elements based entirely on just a few settings of your choice. Baseline grids without the headaches.

Demo

Implementation

Using Typecsset couldn’t be easier. Download the Sass file, predefine any settings, @import it into your project, go!

$typecsset-base-font-size:      18px;
$typecsset-base-line-height:    27px;

[Your own CSS]

@import "path/to/typecsset";

[More of your own CSS]

Example

Precision

Due to the nature of unitless and relative values, you will end up with a lot of floats as opposed to integers (e.g. line-height: 1.333; instead of line-height: 24px;). In order to ensure that browsers can work these values out as closely as possible to the pixel, thus avoiding rounding errors, I recommend compiling your Sass with the --precision flag set to 7, e.g.:

sass --watch typecsset.scss:typecsset.css --style expanded --precision 7

Settings

All Typecsset’s settings are stored in namespaced variables (e.g. $typecsset-base-font-size). You should avoid modifying these directly, as to do so would inhibit your ability to smoothly update the library. If you would like to modify the default settings in Typecsset, predefine them before you import the library, as above.

There are certain settings in Typecsset that should not and cannot be overridden, as they are fundamental to the way the library works. These settings are, however, based upon the settings you can modify.

$typecsset-base-font-size

This is the base font size you would like your project to have. Set this in pixels: Typecsset will convert it to the relevant units for you.

$typecsset-base-line-height

This is the base line height you would like your project to take. Again, define this in pixels: Typecsset will convert it into a unitless value for you.

This $typecsset-base-line-height value is the most important one in the whole library—it defines and underpins your whole vertical rhythm. Everything (margins, line-heights, etc.) will be based upon units of this number in order to maintain a consistent and harmonious vertical rhythm.

$typecsset-h[1–6]-size

These settings, predictably, contain the desired font sizes for your headings one-through-six. Again, they are set in pixels because the library will pick them up and convert them into rems later on.

$typecsset-indented-paragraphs

This is a simple boolean to toggle between indented—as you traditionally find in print—or simply spaced—more common on the web—paragraphs.

$typecsset-show-baseline

Another boolean which will simply turn a baseline grid either on or off. The image used for the grid is provided by Basehold.it, and is based on the value of $typecsset-base-line-height. It will automatically update itself whenever you modify the value of $typecsset-base-line-height.

$typecsset-magic-number

This is a library setting, and cannot/should not be modified. Your magic number—typographically speaking—is the number which underpins your vertical rhythm. This is sourced from your $typecsset-magic-number setting and will define the margins and line-heights for all typographical elements.

$typecsset-magic-ratio

This is another library variable, and simply holds your magic number as a ratio of your chosen base font size.

Tools

Typecsset has a number of mixins and functions which are used to generate more verbose CSS around your own settings.

typecsset-font-size()

This mixin takes a pixel value for a font size and converts it into a rem-with-pixel-fallback font-size, with a unitless line-height based upon your vertical rhythm. Clever stuff!

Input:

$typecsset-base-font-size:      16px;
$typecsset-base-line-height:    24px;

[...]

.foo {
    @include typecsset-font-size(20px);
}

Output:

.foo {
    font-size: 20px;
    font-size: 1.25rem;
    line-height: 1.2;
}
  • font-size: 20px;: A pixel fallback simply lifted straight from the input into the mixin.
  • font-size: 1.25rem; A rem-based font-size for supporting browsers. This is calculated by desired font-size / base font-size = font-size in rems. 20 / 16 = 1.25.
  • line-height: 1.2;: This is a unitless value greater than 1 which, when multiplied by the element’s font-size, yields a number that is a multiple of your base line-height. It is this which keeps everything on your baseline. 1.2 * 20 = 24px.

typecsset-space()

The typecsset-space() mixin simply drops a double amount of ‘spacing’ onto a given property, e.g. padding:

Input:

$typecsset-base-line-height:    24px;

.foo {
    @include typecsset-space(margin-bottom);
}

Output:

.foo {
    margin-bottom: 48px;
    margin-bottom: 3rem;
}

This simple-looking mixin just DRYs out some repeated Typecsset functionality.

typecsset-strip-units()

The typecsset-strip-units() function simply does as it says: it removes the units from a value that is passed into it:

Input:

.foo {
    line-height: typecsset-strip-units(1.5px);
}

Output:

.foo {
    line-height: 1.5;
}

This very useful function only gets used once—to get us our baseline grid image:

[...]

$typecsset-baseline-size: typecsset-strip-units($typecsset-magic-number);

background-image: url(http://basehold.it/i/#{$typecsset-baseline-size}); /* [3] */

[...]

More Repositories

1

inuit.css

Powerful, scalable, Sass-based, BEM, OOCSS framework.
CSS
3,838
star
2

CSS-Guidelines

High-level guidelines for writing manageable, maintainable CSS
3,653
star
3

ct

Let’s take a look inside your <head>…
CSS
1,848
star
4

csswizardry-grids

Simple, fluid, nestable, flexible, Sass-based, responsive grid system.
CSS
1,491
star
5

csswizardry.github.com

My site.
HTML
463
star
6

nudge

Warn developers about improper selector usage
CSS
225
star
7

beautons

A beautifully simple button toolkit
CSS
211
star
8

csscv

A simple, opinionated stylesheet for formatting semantic HTML to look like a CSS file.
CSS
205
star
9

vanilla

My personal starting point for new builds.
HTML
184
star
10

discovr

CSS Architecture workshop files
CSS
172
star
11

frcss

CSS
107
star
12

dotfiles

Starting small… my dotfiles for a few things.
Vim Script
102
star
13

inuit.css-web-template

Web template for housing the inuit.css framework as submodule
CSS
88
star
14

ama

Ask me anything!
58
star
15

recipes

Collection of things I like cooking
42
star
16

pr.ofile.me

Digital, mobile business cards
40
star
17

hry.rbrts.me

Personal hub site.
Racket
20
star
18

build-along-1

The first CSS Wizardry build-along
17
star
19

css-architecture

Workshop materials
CSS
16
star
20

fluid-grids

PHP
15
star
21

extend-vs-mixin

CSS
13
star
22

work

Dedicated ‘work’ page for CSS Wizardry
HTML
12
star
23

fep

9
star
24

sampenrose.co.uk

Portfolio
6
star
25

demo-component

CSS
5
star
26

harry.is

HTML
3
star
27

gilliansibthorpe.com

HTML
2
star
28

questions-for-consultants-issues

Public issue tracker for my eBook, Questions for Consultants
2
star
29

test

1
star
30

wishlist

Because I’m greedy like that…
1
star
31

press

Bios and stuff…
1
star
32

toolkit-core

CSS
1
star
33

piccalilli-burger-menu-demo

HTML
1
star
34

markrabey.github.io

CSS
1
star
35

nightingale-demo

HTML
1
star
36

bower-demo

CSS
1
star