Skip to content

Instantly share code, notes, and snippets.

@jdlehman
Created June 17, 2014 01:06
Show Gist options
  • Save jdlehman/de630d458c15520247c1 to your computer and use it in GitHub Desktop.
Save jdlehman/de630d458c15520247c1 to your computer and use it in GitHub Desktop.
Vertical Rhythm Ex2: Vertical Rhythm Mixin for Case 1 (text-based elements)
<h2>Large Text</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut sollicitudin pulvinar est, vel consequat mauris blandit sed. Duis sed nisl eu dolor laoreet luctus. Ut id vulputate mauris. Sed ac lacus orci. Sed quis metus nisi. Mauris interdum tincidunt tellus, eu cursus sem consequat eu. Vivamus dapibus purus ac purus dictum, ut hendrerit massa varius. In hac habitasse platea dictumst. Suspendisse convallis neque nec felis adipiscing, a volutpat leo laoreet. Pellentesque massa velit, tincidunt nec dolor vel, tincidunt lacinia tellus. Morbi vitae tellus bibendum, commodo tortor a, venenatis turpis. Curabitur vestibulum ut massa sit amet tempus. Fusce nisl mauris, tincidunt quis pulvinar sit amet, consectetur id ante. Maecenas non dapibus leo. Suspendisse interdum tortor eu hendrerit sagittis. Ut eleifend ac neque non convallis.</p>
<ul>
<li>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</li>
<li>Curabitur eget est at massa mattis aliquet.</li>
<li>Sed feugiat lacus non purus vulputate, ac pellentesque augue luctus.</li>
</ul>
// ----
// Sass (v3.3.8)
// Compass (v1.0.0.alpha.19)
// ----
$base-font-size: 16px;
$line-height-ratio: 1.5;
$line-height-base: 1rem * $line-height-ratio;
// restrict font-size to rems so everything scales well
@mixin vertical-rhythm($font-size) {
// determine how many lines this font-size will take up
$multiplier: ceil($font-size / $line-height-base);
font-size: $font-size;
line-height: $line-height-base * $multiplier;
}
h2 {
@include vertical-rhythm(3.4rem);
}
html {
font-size: $base-font-size;
line-height: $line-height-ratio;
background: url(http://basehold.it/i/24);
}
* {
margin-top: 0;
margin-bottom: 0;
padding-top: 0;
padding-bottom: 0;
}
h2 {
font-size: 3.4rem;
line-height: 4.5rem;
}
html {
font-size: 16px;
line-height: 1.5;
background: url(http://basehold.it/i/24);
}
* {
margin-top: 0;
margin-bottom: 0;
padding-top: 0;
padding-bottom: 0;
}
<h2>Large Text</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut sollicitudin pulvinar est, vel consequat mauris blandit sed. Duis sed nisl eu dolor laoreet luctus. Ut id vulputate mauris. Sed ac lacus orci. Sed quis metus nisi. Mauris interdum tincidunt tellus, eu cursus sem consequat eu. Vivamus dapibus purus ac purus dictum, ut hendrerit massa varius. In hac habitasse platea dictumst. Suspendisse convallis neque nec felis adipiscing, a volutpat leo laoreet. Pellentesque massa velit, tincidunt nec dolor vel, tincidunt lacinia tellus. Morbi vitae tellus bibendum, commodo tortor a, venenatis turpis. Curabitur vestibulum ut massa sit amet tempus. Fusce nisl mauris, tincidunt quis pulvinar sit amet, consectetur id ante. Maecenas non dapibus leo. Suspendisse interdum tortor eu hendrerit sagittis. Ut eleifend ac neque non convallis.</p>
<ul>
<li>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</li>
<li>Curabitur eget est at massa mattis aliquet.</li>
<li>Sed feugiat lacus non purus vulputate, ac pellentesque augue luctus.</li>
</ul>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment