[UPDATE]:
I posted an article on Medium as per a suggestion in the comments: https://medium.com/@holmesadrianh/have-you-used-these-css-selectors-5535b9e7b48f
[ORIGINAL]:
I have been working on various types of projects the last few years and what I have found is that for most of the larger projects that I have worked on, it has been more effort using the BEM technique for styling. The main reason is because of how the project, the objectives, whether from client or dev, constantly changes.
What I had done for a more recent project is create some more atomic like classes:
.typo__bold{}
.typo__uppercase{}
.typo__h1{}
I have found this a lot more useful when page specific and component specific changes are required. I also want to mention the environment has been a nightmare to work in so it might be the reason I am considering atomic for a larger project.
So what I have gotten into is using a bit of both BEM and Atomic techniques.
However, I have been researching a bit more about this Atomic approach but a bit more compact and I have run a test that seems to be working fine, but I am not sure about the risks and concerns. Here's the idea, to use tag attributes as selectors:
[bold]{
font-weight: bold;
}
[uppercase]{
text-transform: uppercase;
}
[style-link]{
/* Link styles */
}
Which successfully styles the following accordingly:
<p uppercase>
Lorem ipsum dolor sit amet, <u bold>consectetur adipiscing</u>
elit, sed do eiusmod <span style-link>tempor incididunt</span>
ut labore et dolore magna aliqua.
</p>
Now I really like this simplicity but my first thought is why has this not been done? Or has it been done and I am yet to stumble across this technique? I am very curious about it and would really like to explore it some more but I thought I'd reach out to the community to find out if there are already some concerns and limitations with this approach.
Keep in mind, my intention is to work between the 2 techniques of BEM and Atomic as I find each bring some magic of their own to the table.
Here is a codepen example where you can see the attribute selection working just fine:
https://codepen.io/awinhayden/pen/OBYjjL
Any thoughts and feedback is much appreciated.
Adrian
[EDIT] For some clarity, I do currently use CSS classes, but want to explore this as an alternative. Some challenges I have found with classes is that you need prefixes to avoid conflicts of simple classes, so the classes have to be longer and more descriptive. Also, you need to add the class attribute which can be avoided if you just need a single style change:
<p class="bold"></p>
versus
<p bold></p>
In addition, being tags, they can be added anywhere in the tag. This helps with certain scenarios where the backend code is difficult to navigate.
[EDIT 2] I just realised that for most cases I would be targeting typography more than anything else. I might want to consider things like margins and spacing, but I actually think it would mostly be for typography. Not sure if that changes the interest in this question now :P