Skip to content

Instantly share code, notes, and snippets.

@gavinmcfarland
Last active May 9, 2017 23:55
Show Gist options
  • Select an option

  • Save gavinmcfarland/edb7d9933cccd9b4bdc3d52110a42ea7 to your computer and use it in GitHub Desktop.

Select an option

Save gavinmcfarland/edb7d9933cccd9b4bdc3d52110a42ea7 to your computer and use it in GitHub Desktop.
Example of how to style bespoke layouts for different viewports
<!-- This method requires you to append a suffix to each utility class in your css and gets tedious -->
<div class="span-1/5-tablet span-1/4-desktop">...</div>
<div class="span-4/5-tablet span-1/4-desktop">...</div>
<div class="span-2/4-desktop">...</div>
<!-- This method is clean and easy to write. It also -->
<div span="1/5{{tablet}} 1/4{{desktop}}">...</div>
<div span="4/5{{tablet}} 1/4{{desktop}}">...</div>
<div span="2/4{{desktop}}">...</div>
<!-- which would add a class dynamically in the browser -->
<div span="1/5">...</div>
<!-- One way to achieve this outcome but the technique is so verbose -->
<style>
@media (--mobile) {
#element1, #element2, #element3 {
/* full width */
}
}
@media (--tablet) {
#element1 {
width: 20%;
}
#element2 {
width: 80%;
}
}
@media (--tablet) {
#element1 {
width: 25%;
}
#element2 {
width: 25%;
}
#element3 {
width: 50%;
}
}
</style>
<div id="element-1">...</div>
<div id="element-2">...</div>
<div id="element-3">...</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment