O
O
Oleg2015-05-18 20:41:18
css
Oleg, 2015-05-18 20:41:18

Is it possible to implement something similar in Stylus?

Hello, I started to master Stylus and I had a question. Is it possible somehow to automatically collect all the selectors where there is an sp mixin, for example, into a variable?

$home = 20px 20px 0 0px;
$menu = 12px 12px -222px 0px;
$logo = 120px 120px -122px 0px;

sp($icon)
  width $icon[0]
  height $icon[1]
  background-position $icon[2] $icon[3]

.home
  sp($home)
  
.menu
  sp($menu)
  
.logo
  sp($logo)

To compile something like this:
.home,
.menu,
.logo {
  background: ...;
}
.home {
  width: 20px;
  height: 20px;
  background-position: 0px 0px;
}
.menu {
  width: 12px;
  height: 12px;
  background-position: -222px 0px;
}
.logo {
  width: 120px;
  height: 120px;
  background-position: -122px 0px;
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Petrov, 2015-05-18
@werty1001

You can use +cache

$home = 20px 20px 0 0px;
$menu = 12px 12px -222px 0px;
$logo = 120px 120px -122px 0px;

sp($icon)
  width $icon[0]
  height $icon[1]
  background-position $icon[2] $icon[3]
  +cache('bg')
   background-image: url('')

.home
  sp($home)
  
.menu
  sp($menu)
  
.logo
  sp($logo)

The output will be exactly what you need.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question