Skip to content

Instantly share code, notes, and snippets.

@whizark
Last active October 24, 2022 21:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save whizark/ff753faa30e362b0eec5 to your computer and use it in GitHub Desktop.
Save whizark/ff753faa30e362b0eec5 to your computer and use it in GitHub Desktop.
HTML/CSS/Sass: Aggregation vs Composition #css #sass
<!-- .list is an aggregation of .li -->
<ul class="list">
<li class="list--li li">Item</li>
</ul>
<!-- .list is a composition of .list--li -->
<ul class="list">
<li class="list--li">Item</li>
</ul>
// ----
// Sass (v3.4.9)
// Compass (v1.0.1)
// ----
// HTML/CSS/Sass: Aggregation vs Composition
//
// SEE ALSO:
// CSS/Sass: Robust/Scalable Layered CSS Architecture
// http://sassmeister.com/gist/8e1941924605cc062020
//
// see also:
// http://en.wikipedia.org/wiki/Object_composition
//
// http://twitter.com/whizark
//
// Other ideas
// https://github.com/whizark/xass#ideas
/* ================
1. Element Layer
================ */
li { /* defines generic li styles */ }
ul { /* defines generic ul styles */ }
/* ======================
2. Object Layer (IS-A)
====================== */
.li { /* overrides li stylex */ }
.list { /* overrides ul styles */ }
/* ==========================
3. Component Layer (HAS-A)
========================== */
.list { /* overrides .list styles */ }
.list--li {
/* In case of Aggregation: overrides **.li** styles */
/* In case of Composition: overrides **li** styles */
}
/* ================
1. Element Layer
================ */
li {
/* defines generic li styles */
}
ul {
/* defines generic ul styles */
}
/* ======================
2. Object Layer (IS-A)
====================== */
.li {
/* overrides li stylex */
}
.list {
/* overrides ul styles */
}
/* ==========================
3. Component Layer (HAS-A)
========================== */
.list {
/* overrides .list styles */
}
.list--li {
/* In case of Aggregation: overrides **.li** styles */
/* In case of Composition: overrides **li** styles */
}
<!-- .list is an aggregation of .li -->
<ul class="list">
<li class="list--li li">Item</li>
</ul>
<!-- .list is a composition of .list--li -->
<ul class="list">
<li class="list--li">Item</li>
</ul>
@damsuzzy9
Copy link

TuUkQ8QDojXgM8jC65xf7X

@damsuzzy9
Copy link

TuUkQ8QDojXgM8jC65xf7X

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment