Skip to content

Instantly share code, notes, and snippets.

@inxilpro
Last active August 29, 2015 14:23
Show Gist options
  • Select an option

  • Save inxilpro/fd2f6397392dddf7f1ff to your computer and use it in GitHub Desktop.

Select an option

Save inxilpro/fd2f6397392dddf7f1ff to your computer and use it in GitHub Desktop.
LESS preprocessor idea
/* Source LESS file */
.my-component {
background: #eee;
.subcomponent {
color: #000;
}
&.extreme {
background: red;
.subcomponent {
font-weight: bold;
}
}
}
/* Generated CSS file */
.my-component {
background: #eee;
}
/* Note that it keeps original definition so that even if some of your HTML
doesn't go thru the build system, it will continue to work fine, just won't
be quite as performant. */
.my-component .subcomponent,
.my-component__subcomponent {
color: #000;
}
.my-component.extreme,
.my-component--extreme {
background: red;
}
.my-component.extreme .subcomponent,
.my-component--extreme__subcomponent {
font-weight: bold;
}
<!-- Source HTML file -->
<div class="my-component class-with-no-rules">
<span class="subcomponent">Hello world.</span>
</div>
<div class="my-component extreme class-with-no-rules">
<span class="subcomponent">Hello world.</span>
</div>
<!-- Generated HTML file -->
<div class="my-component class-with-no-rules">
<span class="my-component__subcomponent">Hello world.</span>
</div>
<div class="my-component--extreme class-with-no-rules">
<span class="my-component--extreme__subcomponent">Hello world.</span>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment