Support absolute font sizing in the vertical rhythm module
This commit is contained in:
parent
94af47d1ca
commit
6d2040b86a
@ -14,6 +14,11 @@ The Documentation for the [latest stable release](http://compass-style.org/docs/
|
|||||||
|
|
||||||
The Documentation for the [latest preview release](http://beta.compass-style.org/)
|
The Documentation for the [latest preview release](http://beta.compass-style.org/)
|
||||||
|
|
||||||
|
0.11.4 (UNRELEASED)
|
||||||
|
-------------------
|
||||||
|
|
||||||
|
* Vertical rhythm now supports absolute units like pixels. Set `$relative-font-sizing` to `false` to enable.
|
||||||
|
|
||||||
0.11.3 (06/11/2011)
|
0.11.3 (06/11/2011)
|
||||||
-------------------
|
-------------------
|
||||||
|
|
||||||
|
@ -10,22 +10,43 @@ $default-rhythm-border-style: solid !default;
|
|||||||
// The IE font ratio is a fact of life. Deal with it.
|
// The IE font ratio is a fact of life. Deal with it.
|
||||||
$ie-font-ratio: 16px / 100%;
|
$ie-font-ratio: 16px / 100%;
|
||||||
|
|
||||||
|
// Set to false if you want to use absolute pixes in sizing your typography.
|
||||||
|
$relative-font-sizing: true !default;
|
||||||
|
|
||||||
|
// $base-font-size but in your output unit of choice.
|
||||||
|
// Defaults to 1em when `$relative-font-sizing`
|
||||||
|
$font-unit: if($relative-font-sizing, 1em, $base-font-size) !default;
|
||||||
|
|
||||||
// The basic unit of font rhythm
|
// The basic unit of font rhythm
|
||||||
$base-rhythm-unit: $base-line-height / $base-font-size * 1em;
|
$base-rhythm-unit: $base-line-height / $base-font-size * $font-unit;
|
||||||
|
|
||||||
// The leader is the amount of whitespace in a line.
|
// The leader is the amount of whitespace in a line.
|
||||||
// It might be useful in your calculations
|
// It might be useful in your calculations
|
||||||
$base-leader: ($base-line-height - $base-font-size) * 1em / $base-font-size;
|
$base-leader: ($base-line-height - $base-font-size) * $font-unit / $base-font-size;
|
||||||
|
|
||||||
// The half-leader is the amount of whitespace above and below a line.
|
// The half-leader is the amount of whitespace above and below a line.
|
||||||
// It might be useful in your calculations
|
// It might be useful in your calculations
|
||||||
$base-half-leader: $base-leader / 2;
|
$base-half-leader: $base-leader / 2;
|
||||||
|
|
||||||
|
// True if a number has a relative unit
|
||||||
|
@function relative-unit($number) {
|
||||||
|
@return unit($number) == "%" or unit($number) == "em" or unit($number) == "rem"
|
||||||
|
}
|
||||||
|
|
||||||
|
// True if a number has an absolute unit
|
||||||
|
@function absolute-unit($number) {
|
||||||
|
@return not (relative-unit($number) or unitless($number));
|
||||||
|
}
|
||||||
|
|
||||||
|
@if $relative-font-sizing and not relative-unit($font-unit) {
|
||||||
|
@warn "$relative-font-sizing is true but $font-unit is set to #{$font-unit} which is not a relative unit.";
|
||||||
|
}
|
||||||
|
|
||||||
// Establishes a font baseline for the given font-size in pixels
|
// Establishes a font baseline for the given font-size in pixels
|
||||||
@mixin establish-baseline($font-size: $base-font-size) {
|
@mixin establish-baseline($font-size: $base-font-size) {
|
||||||
body {
|
body {
|
||||||
font-size: $font-size / $ie-font-ratio;
|
font-size: $font-size / $ie-font-ratio;
|
||||||
@include adjust-leading-to(1, $font-size);
|
@include adjust-leading-to(1, if($relative-font-sizing, $font-size, $base-font-size));
|
||||||
}
|
}
|
||||||
html>body {
|
html>body {
|
||||||
font-size: $font-size;
|
font-size: $font-size;
|
||||||
@ -43,12 +64,18 @@ $base-half-leader: $base-leader / 2;
|
|||||||
// to the smallest integer that is large enough to fit the font.
|
// to the smallest integer that is large enough to fit the font.
|
||||||
// Use $from_size to adjust from a non-base font-size.
|
// Use $from_size to adjust from a non-base font-size.
|
||||||
@mixin adjust-font-size-to($to-size, $lines: ceil($to-size / $base-line-height), $from-size: $base-font-size) {
|
@mixin adjust-font-size-to($to-size, $lines: ceil($to-size / $base-line-height), $from-size: $base-font-size) {
|
||||||
font-size: 1em * $to-size / $from-size;
|
@if $relative-font-sizing and $from-size != $base-font-size {
|
||||||
@include adjust-leading-to($lines, $to-size);
|
@warn "$relative-font-sizing is false but a relative font size was passed to adjust-font-size-to";
|
||||||
|
}
|
||||||
|
font-size: $font-unit * $to-size / $from-size;
|
||||||
|
@include adjust-leading-to($lines, if($relative-font-sizing, $to-size, $base-font-size));
|
||||||
}
|
}
|
||||||
|
|
||||||
@mixin adjust-leading-to($lines, $font-size: $base-font-size) {
|
@mixin adjust-leading-to($lines, $font-size: $base-font-size) {
|
||||||
line-height: 1em * $lines * $base-line-height / $font-size;
|
@if $relative-font-sizing and $font-size != $base-font-size {
|
||||||
|
@warn "$relative-font-sizing is false but a relative font size was passed to adjust-leading-to";
|
||||||
|
}
|
||||||
|
line-height: $font-unit * $lines * $base-line-height / $font-size;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calculate rhythm units
|
// Calculate rhythm units
|
||||||
@ -56,7 +83,10 @@ $base-half-leader: $base-leader / 2;
|
|||||||
$lines: 1,
|
$lines: 1,
|
||||||
$font-size: $base-font-size
|
$font-size: $base-font-size
|
||||||
) {
|
) {
|
||||||
$rhythm: 1em * $lines * $base-line-height / $font-size;
|
@if $relative-font-sizing and $font-size != $base-font-size {
|
||||||
|
@warn "$relative-font-sizing is false but a relative font size was passed to the rhythm function";
|
||||||
|
}
|
||||||
|
$rhythm: $font-unit * $lines * $base-line-height / $font-size;
|
||||||
@return $rhythm;
|
@return $rhythm;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -97,19 +127,25 @@ $base-half-leader: $base-leader / 2;
|
|||||||
|
|
||||||
// Apply a border width to any side without destroying the vertical rhythm
|
// Apply a border width to any side without destroying the vertical rhythm
|
||||||
@mixin apply-side-rhythm-border($side, $width: 1px, $lines: 1, $font-size: $base-font-size, $border-style: $default-rhythm-border-style) {
|
@mixin apply-side-rhythm-border($side, $width: 1px, $lines: 1, $font-size: $base-font-size, $border-style: $default-rhythm-border-style) {
|
||||||
|
@if $relative-font-sizing and $font-size != $base-font-size {
|
||||||
|
@warn "$relative-font-sizing is false but a relative font size was passed to apply-side-rhythm-border";
|
||||||
|
}
|
||||||
border-#{$side}: {
|
border-#{$side}: {
|
||||||
style: $border-style;
|
style: $border-style;
|
||||||
width: 1em * $width / $font-size;
|
width: $font-unit * $width / $font-size;
|
||||||
};
|
};
|
||||||
padding-#{$side}: 1em / $font-size * ($lines * $base-line-height - $width);
|
padding-#{$side}: $font-unit / $font-size * ($lines * $base-line-height - $width);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Aplly rhythm borders equally to all sides
|
// Aplly rhythm borders equally to all sides
|
||||||
@mixin rhythm-borders($width: 1px, $lines: 1, $font-size: $base-font-size, $border-style: $default-rhythm-border-style) {
|
@mixin rhythm-borders($width: 1px, $lines: 1, $font-size: $base-font-size, $border-style: $default-rhythm-border-style) {
|
||||||
|
@if $relative-font-sizing and $font-size != $base-font-size {
|
||||||
|
@warn "$relative-font-sizing is false but a relative font size was passed to rhythm-borders";
|
||||||
|
}
|
||||||
border: {
|
border: {
|
||||||
style: $border-style;
|
style: $border-style;
|
||||||
width: 1em * $width / $font-size; };
|
width: $font-unit * $width / $font-size; };
|
||||||
padding: 1em / $font-size * ($lines * $base-line-height - $width);
|
padding: $font-unit / $font-size * ($lines * $base-line-height - $width);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Apply a leading rhythm border
|
// Apply a leading rhythm border
|
||||||
|
Loading…
Reference in New Issue
Block a user