For a new project i use the amazing Foundation framework to build an large responsive website. And i love it! The framework includes the modular scale approach by Tim Brown. You’ll find more informations here: http://foundation.zurb.com/docs/typography.php
A drawback for responsive websites is, that Foundation using px to define all font sizes. But we want different font-sizes for different devices and screens. So we have to teach Foundation to speak in em. And that’s the way:
1. Define the modular scale parameters
Set the variables in your _settings.scss file
$ratio: 1.5; $baseFontSize: 14px; $importantModNum: 40px; $base-size: $baseFontSize $importantModNum;
and add these variables for the modular scale function by Scott Kellum.
$round-pixels: false;
The last variable is missing in the Foundation settings file. But it doesn’t work correctly without. By default all numbers are floored and that means sometimes you get identical values back.
2. px2em function
The modular scale function returns only px values. You need a simple SASS function to convert px to em:
@function px2em ($font_size, $base_font_size: $baseFontSize) {
@return ($font_size / $base_font_size) + em;
}
I used my px2em function and just change the base-font-size variable. In your .scss files use now px2em(ms(0)) for example to get 1em and px2em(ms(2)) to get 1.5em. Here is a list of all values depending on my parameters: http://modularscale.com/scale/?px1=14&px2=50&ra1=1.5&ra2=0
3. Reset all font sizes to em
Last of all you must change the Foundation font settings to em. By default it’s your $baseFontSize. Just add this line in your app.scss:
body, div, dl, dt, dd, ul, ol, li, h1, h2, h3, h4, h5, h6, pre, form, p, blockquote, th, td, section, article, footer, header, nav {
font-size: 1em;
}
and set
html {
font-size: $baseFontSize;
}
After that you can write your media queries for example like that to increase the font size on very large screens:
@media only screen and (min-width: 1441px) { /* aka very large */
html {
font-size: 18px;
}
}
Here you can check some different modular scale values: http://modularscale.com/