0
Is it possible to retrieve a part of a class name in an element and pass as value to the CSS property using Stylus? Example
.font-word-spacing-light--1 { word-spacing: -0.1px !important } .font-letter-spacing-light--1 { letter-spacing: -0.1px !important } .align-left--16px { position relative left -16px }
In this case, use in the element as follows
<h2 class="font-word-spacing-light--1 font-letter-spacing-light--1 align-left--16px">Elemento</h2>
In this case, I wondered if this is possible, as vuetify does something like this, I wondered if it is possible, there are for example the color classes
cor-vermelha /* cor de fundo vermelha */ cor-vermelha--text /* cor da fonte vermelha */
I read in the manual that there are Mixins, Variables and Functions I just did not understand right how to use and it makes possible what I mentioned
Let’s say something practical would look like this (I’m just exemplifying with some syntax)
<h2 class="cor-do-texto--ff00ff tamanho-do-texto--60">
Título com cor #ff00ff e tamanho 60PX
</h2>
<style lang="stylus">
.cor-do-texto--{%s}
color #{%s} /* imprime color: #ff00ff */
.tamanho-do-texto--{%s}
text-size {%s}PX /* imprime text-size: 60px */
</style>
resolution if someone comes here with the same doubt
maxkw = 7680
width(n)
width n !important
min-width(n)
min-width n !important
max-width(n)
max-width n !important
.width
for r in 0..maxkw
&-{r}
width(1px * r)
for r in 0..maxkw
&-v-{r}
width(1vw * r)
for r in 0..maxkw
&-per-{r}
width(1% * r)
.min-width
for r in 0..maxkw
&-{r}
min-width(1px * r)
for r in 0..maxkw
&-v-{r}
min-width(1vw * r)
for r in 0..maxkw
&-per-{r}
min-width(1% * r)
.max-width
for r in 0..maxkw
&-{r}
max-width(1px * r)
for r in 0..maxk
&-v-{r}
max-width(1vw * r)
for r in 0..maxkw
&-per-{r}
max-width(1% * r)
maxkh = 4320
height(n)
height n !important
min-height(n)
min-height n !important
max-height(n)
max-height n !important
.height
for r in 0..maxkh
&-{r}
height(1px * r)
for r in 0..maxkh
&-v-{r}
height(1vh * r)
for r in 0..maxkh
&-per-{r}
height(1% * r)
.min-height
for r in 0..maxkh
&-{r}
min-height(1px * r)
for r in 0..maxkh
&-v-{r}
min-height(1vh * r)
for r in 0..maxkh
&-per-{r}
min-height(1% * r)
.max-height
for r in 0..maxkh
&-{r}
max-height(1px * r)
for r in 0..maxkh
&-v-{r}
max-height(1vh * r)
for r in 0..maxkh
&-per-{r}
max-height(1% * r)
It’s not possible, that’s not the purpose of Stylus. You would have to have a class for each item you want to style, as the code needs to be processed to turn CSS. In that case, I think it is more advantageous to switch the properties of the element directly with JS.
– Renan Gomes
@Renan understood, I imagined, what a pity that functions do not work like this
– flourigh