I feel this is somewhat of a philosophical question, but for the sake of keeping things grounded (per Stackoverflow requirements), here is a specific case in which the answer to this general question would be helpful:
I want to insert space after a styled element. How can I do this properly?
I’ve identified a few ways in which I can add the space:
- Create a “spacer” div
- Create a “margin-X-px” helper class and append the class to the element’s class attribute list
- Set the margin property of the style attribute of the element within HTML
- Create an "ID" for the element and add the margin with vanilla CSS
- Sub-class the styled class with vanilla CSS
- Use SCSS @extend to sub-class the styled class and absorb this into one class attribute
With a number of CSS frameworks becoming the norm, I am seeing code which may traditionally be considered "incorrect" due to a mixing of concepts. I've noticed that these infractions tend to occur as part of a tradeoff between modularity and simple semantics. To me, it appears as though style and structure are inherently dependent upon one another. For example, one may need to create a parent DIV structure for the sole purpose of inserting some style.
Personally, I feel it makes the most sense to do whatever is most semantic for one's required modularity needs: If there were no need for modularity (one-shot class), I would append to the "style" attribute within the actual HTML until a point was reached in which the meaning of this code could be made clearer by abstracting into a CSS class. If I planned to re-use this element, I may make a CSS class for even a simple element which could be expressed semantically in the "style" attribute.
What are your thoughts regarding this approach?
Thank You!