A
A
Anatoly Terkov2016-02-02 04:28:37
css
Anatoly Terkov, 2016-02-02 04:28:37

Does any CSS preprocessor have a way to generate classes dynamically from HTML (see more)?

Hello.
I am a supporter of people who write something like this:

<p class="my-article">
Lorem ipsum
</p>
<p class="my-article margin-top-13 margin-left-32">
Lorem ipsum
</p>
<p class="my-article">
Lorem ipsum
</p>

Well, and accordingly CSS:
.my-article{
color: blue;
}
.margin-top-13{
margin-top: 13px;
}
.margin-left-32{
margin-left: 32px;
}

In this case, of course, there is no particular need for this. Although, depending on what design.
I'm wondering if there's a miracle that can generate classes when they're accessed via HTML?
For example, something like this:
/* допустим, что это синтаксис less */
[email protected]{px}{
margin-left: @px;
}

That is, so that when accessing from HTML with the margin-left-432942839 class in CSS, exactly such a class and with such pixels would be created.
Is it possible / is there such a thing?
Or how is it possible to do it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Сергей delphinpro, 2016-02-02
@MrBasta

Стрёмные классы конечно, ну да ладно, дело ваше :)
Подобных плагинов я не встречал, но если вам так хочется, могу предложить один приемчик.
В препроцессорах есть циклы. Нагенерируйте классов через них, а потом конечный css прогоните через uncss, чтобы удалить неиспользуемые :)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question