Exploring the capabilities of Stylus, I set out to replicate a standard CSS list of selectors with uniform properties such as (example 1)
.col-01, .col-02, .col-03 { display : block }
by utilizing Stylus'
push()
function. However, this approach encounters issues when attempting the following:
sizes = small medium large
for size, i in sizes
for num in ( 1..12 )
columns = push( .column-{size}-{num} )
Instead, by structuring the code as follows:
sizes = small medium large
for size, i in sizes
for num in ( 1..12 )
.column-{size}-{num}
display block
float left
The functionality is achieved, albeit generating verbose compiled CSS.
.column-small-1 { display: block; float: left }
.column-small-2 { display: block; float: left }
.column-small-3 { display: block; float: left }
etc
An alternative method using Stylus' @extend
feature can emulate example 1, although with some workaround involved:
.column
float left
sizes = small medium large
for size, i in sizes
for num in ( 1..12 )
.column-{size}-{num}
@extend .column
This technique successfully reproduces the intended output.
EDIT:
To differentiate a class declaration, utilize $
instead of .
— preventing the original class from generating any compiled css
$column
float left
sizes = small medium large
for size, i in sizes
for num in ( 1..12 )
.column-{size}-{num}
@extend .column