0

Is this possible to pass the the number from class name to LESS ?

I would like to pass the number (1, 2, 3, 4...) as a variable to my LESS file. Then use this number to generate CSS.

Here is the example:

                        <div class="flex">
                            <div class="flex-1">
                                    FLEX 1
                            </div>
                            <div class="flex-2">
                                    FLEX 2
                            </div>
                        </div>

I would like to receive the CSS like below:

flex-NUMBER{
   flex: NUMBER
}

Where NUMBER is the number from my class name.

If this is possible, could you please tell me how I can do that ?

seven-phases-max
  • 11,765
  • 1
  • 45
  • 57
Paweł Stanecki
  • 454
  • 2
  • 10
  • 24
  • 1
    You mean to get the _number_ from the markup? ... If yes, then no, you can't do that as LESS have no info about the markup, it simply is a compiler to generate CSS. Are you trying to count items and add CSS accordingly, or what are you trying to do? – Asons Nov 06 '17 at 10:14
  • I will explain... I dont want to type css to every `.flex-NUMBER` class every time I would use it. I would like from less to make it autmatically. If I type in html file for example class `.flex-5` I would like LESS to make the `.flex-5{ flex: 5; }` in my css file automatically, if I type `.flex-2` in html I would like LESS to make `.flex-2{ flex: 2; }` in css file... etc. – Paweł Stanecki Nov 06 '17 at 10:30
  • 1
    Can't see how that is possible since LESS has no connection with the html file, and LESS is executed server side and when arriving the browser it is only CSS, which can't access the html. – Asons Nov 06 '17 at 10:43
  • Duplicate of https://stackoverflow.com/questions/31275436, https://stackoverflow.com/questions/40993082, https://stackoverflow.com/questions/28775914, https://stackoverflow.com/questions/27097530, https://stackoverflow.com/questions/17104746 etc. – seven-phases-max Nov 06 '17 at 11:19

0 Answers0