Code Monkey home page Code Monkey logo

typesettings's Introduction

npm GitHub release GitHub license Gitter

Typesettings

Set your type in Ems with modular scale, vertical rhythm, and responsive ratio based headlines using Sass. Why create another type toolkit in Sass? I wanted to and I couldn't find exactly what I was looking for. Typesettings uses techniques from many different amazing tools while trying to keep it simple.

  • Its only dependency is Sass
  • It uses Ems not REMs or pixels
  • Handles all the math for Ems including the compounding
  • It maintains vertical rhythm with pixel based borders using padding set in Ems
  • It comes with a default 6px baseline to maintain rhythm on all block elements
  • It relies more on using Sass functions combined with vanilla CSS rules rather than mixins to style
  • It uses modular scale values to set font-size
  • It has optional default type styles that includes settings for adjusting headlines based on screen width

How to setup

There are four ways you can download Typesettings.

  • Download the latest release
  • Clone the repo: git clone https://github.com/ianrose/typesettings.git
  • Install with Bower: bower install typesettings --save
  • Install with npm: npm install typesettings --save

To start using Typesettings @import the _typesettings.scss partial into your Sass project after your CSS reset.

There is also the bundled single file versions. For example, using Typesettings on Codepen or you are looking to simply copy and paste Typesettings into your project. You can also start by @import the _typsettings.bundle.scss into your Sass project after your CSS reset.

 @import "path/your-reset";

 // Your settings for Typesettings :)
 $font-sans: 'Helvetica Neue', Helvetica, Arial, sans-serif;
 $font-serif: Georgia, 'Times New Roman', serif;
 $font-mono: 'Lucida Console', Monaco, monospace;
 $text-color: #000;
 $base-vertical-unit: 6px;
 $base-line-multi: 4;
 $base-font-size: 16px;
 $ms-ratio: 1.414;
 $paragraph-indent: true;
 $paragraph-justify: true;
 $load-typesetted: true;
 $global-init: false; // By default set to false, loaded with typesetted

 @import "path/typesettings"; // Here is the _typesettings.scss partial

 @import "path/your-styles";

Advanced Usage

You have the ability to easily import Typesettings' mixins, functions, and internal variables separately and use them how you see fit within your project. For example:

 @import "path/your-reset";

 // Your settings for Typesettings :)
 $font-sans: 'Helvetica Neue', Helvetica, Arial, sans-serif;
 $font-serif: Georgia, 'Times New Roman', serif;
 $font-mono: 'Lucida Console', Monaco, monospace;
 $text-color: #000;
 $base-vertical-unit: 6px;
 $base-line-multi: 4;
 $base-font-size: 16px;
 $ms-ratio: 1.414;

 // Import only the functionality of Typesettings you want
 @import "path/typesettings/settings";
 @import "path/typesettings/internal";
 @import "path/typesettings/functions";
 @import "path/typesettings/mixins";

 @include typesettingsInit();

 @import "path/your-styles";

How to use

After Typesettings is setup in your project the default type styles should be looking good. However I bet you want to use modular scale and vertical rhythm in the rest of your project. Here is an example of how to do that:

The Scss:

// This example is using Typesettings' default settings
// [1] 3 times the baseline grid value for margin-bottom.
// The second argument is the context font-size. In this case it is 1 step down in
// the modular scale.
//
// [2] Using an optional mixin, a 2px border bottom is set with padding bottom
// set to 3 times the baseline grid with 2px subtracted. By subtracting the 2px from
// the padding bottom, vertical rhythm is maintained.
//
// [3] Using an optional mixin, the line-height is set to 3 * baseline grid. Then
// the font-size is passed using our modular scale value.
.your-module {
   margin-bottom: emRhythm(3, $ms-down1); // [1]
   border-color: #000;
   border-style: solid;
   @include rhythmBorderBottom(2px, 3, $ms-down1); // [2]
   @include setType(3, $ms-down1); // [3]
}

The outputted CSS:

.your-module {
    margin-bottom: 1.59075em; /* 18px */
    border-color: #000;
    border-style: solid;
    border-bottom-width: 2px;
    padding-bottom: 1.414em; /* 16px */
    font-size: 0.70721em;
    line-height: 1.59075; /* 18px (Okay, not pixel perfect, 17.9999999999px) */
}

You can also look at the source code of the document site to see how it was made using Typesettings.

Requirements

Sass or Stylus, that's it.

Precision

Typesettings uses relative units and many of the values outputted are a result of dividing and multiplying. So a computed pixel value like 17.999999px will sometimes happen.

Thanks and Resources

Please ask questions on Gitter and use GitHub issues for bugs.

License

The MIT License (MIT)

typesettings's People

Contributors

bitdeli-chef avatar ghosh avatar ianrose avatar johngerome avatar paolodina avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

typesettings's Issues

Add to Bower

Provide the user with the ability to manage typesettings using bower.

REMs instead of EMs

Hi there,

This is pretty much what I was looking for :) Is there any specific reason not to use REMs?

Thanks!

Re-think static media queries on headlines

If the user wanted to adjust the media queries for the headline sizes when using bower they have to re-write the styles and overwrite.

  • Consider removing the media queries from typesettings and instead show examples of how you could use media queries and typesettings to adjust headline size
  • Create adjustable breakpoint settings for the headlines. This adds complexity and could cause conflicts if the user likes to use a Sass tool to handle breakpoints.

Document mixins

The mixins are documented pretty well in the partial, but web documentation would be better, with examples.

Note I'm not being critical, this is a great project, just documenting the need. ๐Ÿ‘

More agnostic?

Hey, i was thinking of switchin from compass to something else (compass is giving hard times with my machine)

I was reading the code and found that you apply some default styles on some elements (font-family, text-transform and such ) which would mean id have to reset them once again in my styles (I always have a _typography.scss file which i style all my h and p )

My question is, wouldn't it be more useful if this library didnt set any default style but gives you only the mixins you need to set the vertical rhythm?

not getting nice results in multi line headings

After following the regular set up...
settings:

$font-sans: $myBod
$font-serif: $Archer
$font-mono: 'Lucida Console', Monaco, monospace
$text-color: #000
$base-vertical-unit: 6.1px
$base-line-multi: 4
$base-font-size: 18px
$ms-ratio: 1.51
$paragraph-indent: true
$paragraph-justify: true
$load-typesetted: true

Looks great on the paragraph font but not on the multi line headings...
working through a solution now.
see a sample here.

http://rejmyre.codey.hosting/style.php
Thanks Ian

Debug baseline overlay

A requested feature is to have the ability to toggle base overlay for both base type baseline and the base vertical unit baseline.

Setting margins and paddings

Full disclosure; new to Sass and currently in the process of getting to know typography a lot better.

So, if I want to keep a consistent vertical rhythm, this is how I set my margins/paddings ?

margin-bottom: emRhythm(5)

Just a few quick questions more.

I see a variable called $base-line-multi, what is it its purpose and how can it be used ?

Can I change the modular scale ratio to some other ?

I don't quite get the logic behind the emRhythm function.

.test {
  margin-bottom: emRhythm(4, $ms-down1);
}

Shouldn't increasing the ms-down-1 to ms-up4, for example, be resulting in a bigger margin? Yet, the value decreases.

Also, in the source file you provide to see the styles applied to typesettings website, sometimes you use the emRhythm function with just one parameter, and sometimes with $ms-X.

That produces different results, what is the reasoning behind that usage ?

Sorry for all the simple questions !!

Hardcoded values?

When setting $load-typesetted to true, the output doesn't seem to honor the value of $base-line-multi. Looking at the source code reveals that there are a lot of hard coded values of $base-line-multi.

For example:
Line 200 of _typesettings.scss:

margin-bottom: emRhythm(4, $ms-up2);

Shouldn't the variable $base-line-multi be used instead of the hardcoded number '4'?

Is it possible to change the scale ratio

I am trying to change the scale ratio to a different one than 1.414. But providing other modular scale ratios doesn't have any effect on the outputed CSS.

It always outputs the values used by the default ratio. If I change base font size for example, I can see the changes, so it is not due to some compile error on my side.

Am I missing something obvious?

Feature Request: Baseline Grid Visual Toggle

Glad to see you've made some updates to this, Ian. Here is a small feature for optionally highlighting the baseline grid that I'd really love to see rolled in at some point, for the purpose of debugging.

$baseline: 1.375;
$showBaselineGrid: scrolling; // options: scrolling | fixed | false
$baselineGridColor: rgba(0, 200, 250, 0.25);

/* Apppend a baseline grid to the body if enabled, according to pref set in the top */
@if $showBaselineGrid == scrolling {
  body {
    background-image: linear-gradient($baselineGridColor 1px, transparent 1px);
    background-size: 100% $baseline#{"em"};
    background-repeat: repeat-y;
  }
}@else if $showBaselineGrid == fixed {
  body:after {
    content: '';
    display: block;
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    pointer-events: none;
    background-image: linear-gradient(rgba(0, 0, 255, 0.1) 1px, transparent 1px);
    background-size: 100% $baseline#{"em"};
  }
}

I am just not sure how to assign a value to $baseline using the unitlessRhythm() function, where I know the value is being generated.

Add a Stylus Version ?

Hello @ianrose ,

Can i make a stylus version of this ? cause i didn't see any of it. I would love to convert this one and it's gonna be a big help on a stylus user.
Thank You.

Good vertical rhythm

How good vertical rhythm look likes based on this settings? i have tried to use another font-faces and could figure out and configure to look good. and for example where should margin be before red line (debug grid) or outside?

Either indent or space, not both

First of all... thanks a lot for this. But could you let us choose weither to divide paragraphs inte EITHER space OR indentation. Both of these are typographically correct. But to use both of them at the same time is not. :) Could you put this logic into the library?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.