What to do when you have sub elements that have sub elements? How to name them?
Always namespace to the module name + __
+ the sub element no matter what?
<section class="foo">
<!-- Regular sub element -->
<div class="foo__chart">
I'm a chart
</div>
<!-- Another sub elements with sub elements -->
<div class="foo__data">
<p class="foo__title">I'm the title</p>
<p class="foo__subtitle">I'm the subtitle</p>
<p class="foo__description">I'm the description</p>
</div>
</section>
Or should I do something like this?
<section class="foo">
<!-- Regular sub element -->
<div class="foo__chart">
I'm a chart
</div>
<!-- Another sub elements with sub elements -->
<div class="foo__data">
<!-- Should I use multiple levels of hierarchy? -->
<p class="foo__data__title">I'm the title</p>
<!-- Or should I go with something like this? -->
<p class="foo-data__subtitle">I'm the subtitle</p>
<!-- I can also forget about my parent and start a new module? -->
<p class="data-subtitle">I'm the description</p>
</div>
</section>
Your help will be much appreciated.
I'll use "bar" instead of "data" because it's meaningless. If "bar" could be considered as an independent block (usable outside of the foo context with the same look), I'm doing this :
If foo's bars are considered as blocks and elements, I'm doing this :
If foo's bar elements have some specificities and some commons (vs. independent bars), or if bar nesting is possible I'm going more verbose but safer (avoid the child > selector) :
Hope it helps