css - SASS rule reuse -



css - SASS rule reuse -

i have set of icons different colors , each color used different status declared css classes. example, <span class="icon icon--app"><span> gives grayness app icon while <span class="icon icon--app icon__light icon__selected"><span> gives white app icon.

the next code written in scss.

span.icon { display: inline-block; width: 32px; height: 32px; &.icon--app { background: url(../images/app_gray.png); &.icon__selected { background: url(../images/app.png); } &.icon__light { background: url(../images/app_gray.png); &.icon__selected { background: url(../images/app_white.png); } } } &.icon--device { background: url(../images/device_gray.png); &.icon__selected { background: url(../images/device.png); } &.icon__light { background: url(../images/device_gray.png); &.icon__selected { background: url(../images/device_white.png); } } } }

the problem is, there's long list of css rules above, shares much similarity app , device , other icons. wonder if can simplify these css rules using sass?

i created mixin you:

@mixin icon($type) { &.icon--#{$type} { background: url(../images/#{$type}_gray.png); &.icon__selected { background: url(../images/#{$type}); } &.icon__light { background: url(../images/#{$type}); &.icon__selected { background: url(../images/#{$type}_white.png) } } } } span.icon { display: inline-block; width: 32px; height: 32px; @include icon(app); @include icon(device); }

css sass

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -