I'm trying to avoid long chain of selectors and use one class-based selector that is automatically created when the LESS CSS is being compiled into plain CSS. See the example below for details.
Inspired by http://css-tricks.com/efficiently-rendering-css/, I had the idea of creating unique classes for each element (duplicate class can intentially be beneficial) to increase efficiency of CSS rendering.
HTML
<div class="main">
<img src="something.jpg" />
<a class="link" href="#">Click me</a>
</div>
LESS CSS
div.main {
img {border:1px solid #ccc;}
a.link {color:blue;}
}
Standard Plain CSS (compiled from LESS above)
div.main img {border:1px solid #ccc;}
div.main a.link {color:blue;}
Desired Plain CSS (compiled from LESS above, the class for the child element within a parent is formatted like
.parentElement1-parentClass1-childElement1-childClass1
, use null
if class is undefined)
.div-main-img-null {border:1px solid #ccc;}
.div-main-a-link {color:blue;}
Of course, more specific/descriptive class name for the element can solve this problem, but for much larger applications and to avoid duplicate class names, this approach might be better since readability is handled by less and the production css is efficient. The "body" element is used as the base and everything else is relative to it in terms of nomenclature. The class name in the html still has to be manually defined to match this requirement, but there's a possibility of creating a script to automate class name creation for all elements.
I was wondering if LESS can have compile method with this criteria in mind. What's your thought on the idea and if something like this is viable?