Skip to content

Instantly share code, notes, and snippets.

@torkiljohnsen
Last active December 14, 2015 08:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save torkiljohnsen/5061018 to your computer and use it in GitHub Desktop.
Save torkiljohnsen/5061018 to your computer and use it in GitHub Desktop.
Example of the issue at hand: .nav gets imported multiple times
@import 'nav'; // "Extending" .nav
.nav--horizontal {
/* horizontal nav is a variant of nav */
}
@import 'nav'; // "Extending" .nav
.nav--vertical {
/* vertical nav is a variant of nav too */
}
.nav {
/* base class */
}
<html>
<head>
<link href="site.css" rel="stylesheet" />
</head>
<body>
<ul class="nav nav--vertical">
<li>Menu item in vertical menu</li>
<li>Menu item in vertical menu</li>
</ul>
<ul class="nav nav--horizontal">
<li>Menu item in horizontal menu</li>
<li>Menu item in horizontal menu</li>
</ul>
</body>
</html>
@import 'nav--horizontal';
@import 'nav--vertical';
/*
The output here will show .nav twice in the compiled css.
Challenge here is that variants of nav should be independent and should
not know about one another, but should still avoid importing nav twice.
Example scenario:
-----------------
Mr Widget Maker may make widgetA, while Dr Widget Master makes widgetB.
They use two different .nav variants. Mrs Clever Siteowner decides to
put both widgetA and widgetB on the same website, thus .nav will be
imported twice in this case.
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment