Automatically choses a typeface width, so the content fits, without jQuery.
Originally by Chris Lewis & Nick Sherman. Vanilla FTW! version by Kenneth Ormandy, with CommonJS support for Browserify, Webpack, etc.
Font-To-Width is a small JavaScript routine which fits text to the width of an element using multiple font styles of different widths.
Originally by Chris Lewis & Nick Sherman, this version has been modified by Kenneth Ormandy to remove the dependency on jQuery.
To install the module through npm, run the following command:
npm install --save @kennethormandy/font-to-width
Then, within your project, require Font to Width:
var FontToWidth = require'@kennethormandy/font-to-width'
Or, if you’re using ES6/2015/whatever:
import FontToWidth from '@kennethormandy/font-to-width' var els = documentquerySelectorAll'.js-ftw' var ftw = elements: els fonts: fontFamily: 'Hardware Regular' fontFamily: 'Hardware Condensed' fontFamily: 'Hardware Compressed'
Alternatively, you can include the font-to-width file in your build process manually, or even reference the file directly:
Note you’ll probably want to replace master
with a specific version number if you take this approach
Text To Fit
display: block
or inline-block
All options are optional.
Name | Default | Description |
---|---|---|
fonts | A list of font-family names or sets of CSS style parameters. If empty, existing fonts are scaled to fit | |
elements | .ftw , .font-to-width , .fonttowidth |
A CSS selector or jQuery object specifying which elements should apply FTW |
minLetterSpace | -0.04 |
A very small, probably negative number indicating degree of allowed tightening |
minFontSize | 1.0 |
Allow scaling of font-size to this ratio of original |
maxFontSize | 1.0 |
Allow scaling of font-size to this ratio of original |
preferredFit | 'tight' |
Whether to prefer 'tight' or 'loose' letterspacing |
preferredSize | 'large' |
Whether to prefer 'large' or 'small' font-size |
2016-05-29
elements
2016-05-28
2015-03-04
2015-02-28
2014-03-31 Initial release
Copyright © 2016–2017 Kenneth Ormandy
Copyright © 2014–2015 Chris Lewis and Nick Sherman