Last active
August 29, 2015 14:10
-
-
Save whizark/6355c4060cb1a35165d7 to your computer and use it in GitHub Desktop.
Sass: The Way to Define Robust CSS Module/Component #sass
This file contains hidden or 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
<ul class="horizontal-list"> | |
<li class="horizontal-list\item">Item</li> | |
<li class="horizontal-list\item">Item</li> | |
<li class="horizontal-list\item">Item</li> | |
</ul> |
This file contains hidden or 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.4.7) | |
// Compass (v1.0.1) | |
// ---- | |
// Sass: The Way to Define Robust CSS Module/Component | |
// | |
// Using back-slash as the namespace separator in HTML/CSS | |
// https://gist.github.com/whizark/ea2ba0ff3f47956fda0f | |
// | |
// Other ideas | |
// https://github.com/whizark/xass#ideas | |
// You may use single back-slash as the namespace | |
// for Mixin/Function/Placeholder selector in Sass, | |
// but you must use double back-slash in CSS. | |
// The reason I use placeholder for base definitions, | |
// wrap it with mixin | |
// and use mixin in other modules/client code is | |
// that extending is fragile and a bad practice for extension. | |
// Mixin encapsulates inner extending in this case. | |
// Module Definitions | |
// ======================== | |
// Defines base styles | |
// for Horizontal List. | |
%vendor\\horizontal-list { | |
list-style: none; | |
margin: 0; | |
padding: 0; | |
} | |
// Wraps base styles and extends them | |
// for Horizontal List. | |
@mixin vendor\\horizontal-list($spacing: .5em) { | |
// Wraping placeholder, it reduces duplicated code | |
// and it's opened for extension. | |
@extend %vendor\\horizontal-list; | |
// Lobotomized Owl Selector | |
// http://alistapart.com/article/axiomatic-css-and-lobotomized-owls | |
> * + * { | |
margin-left: $spacing; | |
} | |
} | |
// Defines base styles | |
// for Horizontal List Item. | |
%vendor\\horizontal-list\\item { | |
display: inline-block; | |
margin: 0; | |
padding: 0; | |
} | |
// Wraps base styles and extends them | |
// for Horizontal List Item. | |
@mixin vendor\\horizontal-list\\item() { | |
@extend %vendor\\horizontal-list\\item; | |
} | |
// Client Code: Concrete Classes | |
// ===================================================== | |
// Using mixin, it may accept arguments | |
// and it's closed for modification. | |
.horizontal-list { | |
@include vendor\\horizontal-list(); | |
} | |
.horizontal-list\\item { | |
@include vendor\\horizontal-list\\item(); | |
} |
This file contains hidden or 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
.horizontal-list { | |
list-style: none; | |
margin: 0; | |
padding: 0; | |
} | |
.horizontal-list\\item { | |
display: inline-block; | |
margin: 0; | |
padding: 0; | |
} | |
.horizontal-list > * + * { | |
margin-left: 0.5em; | |
} |
This file contains hidden or 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
<ul class="horizontal-list"> | |
<li class="horizontal-list\item">Item</li> | |
<li class="horizontal-list\item">Item</li> | |
<li class="horizontal-list\item">Item</li> | |
</ul> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment