Last active
August 29, 2015 14:03
-
-
Save jdlehman/1ed9ccf7a937494141ab to your computer and use it in GitHub Desktop.
Vertical Rhythm Ex 3: Handle height-based elements
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> | |
<div class="box"> | |
<span>Lorem ipsum</span> | |
</div> | |
<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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ---- | |
// Sass (v3.3.14) | |
// Compass (v1.0.1) | |
// ---- | |
$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, $use-height: false) { | |
// determine how many lines this font-size will take up | |
$multiplier: ceil($font-size / $line-height-base); | |
@if $use-height { | |
// determine leftover height that needs to be filled to take | |
// up a whole number of lines | |
$leftover: $line-height-base * $multiplier - $font-size; | |
height: $font-size; | |
margin-top: $leftover / 2; | |
margin-bottom: $leftover / 2; | |
} | |
@else { | |
font-size: $font-size; | |
line-height: $line-height-base * $multiplier; | |
} | |
} | |
h2 { | |
@include vertical-rhythm(3.4rem); | |
} | |
.box { | |
@include vertical-rhythm(5.2rem, $use-height: true); | |
background-color: blue; | |
width: 200px; | |
} | |
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; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
h2 { | |
font-size: 3.4rem; | |
line-height: 4.5rem; | |
} | |
.box { | |
height: 5.2rem; | |
margin-top: 0.4rem; | |
margin-bottom: 0.4rem; | |
background-color: blue; | |
width: 200px; | |
} | |
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; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> | |
<div class="box"> | |
<span>Lorem ipsum</span> | |
</div> | |
<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