Пругасти градијент мешавина - ЦСС-трикови

Anonim

Популаран начин цртања пруга у ЦСС-у за дефинисање линеарног градијента са преклапајућим заустављањима у боји. Ради врло добро, али није баш згодно ручно писати ... Идеја од милијарду долара: помоћу Сасс-а га аутоматски генеришете са листе боја!

/// Stripe builder /// @author Hugo Giraudel /// @param (Direction) $direction - Gradient direction /// @param (List) $colors - List of colors /// @output `background-image` if several colors, `background-color` if only one @mixin stripes($direction, $colors) ( $length: length($colors); @if $length > 1 ( $stripes: (); @for $i from 1 through $length ( $stripe: (100% / $length) * ($i - 1); @if $i > 1 ( $stripes: append($stripes, nth($colors, $i - 1) $stripe, comma); ) $stripes: append($stripes, nth($colors, $i) $stripe, comma); ) background-image: linear-gradient($direction, $stripes); ) @else if $length == 1 ( background-color: $colors; ) )

Употреба

body ( @include stripes(to right, #8e44ad #2c3e50 #2980b9 #16a085 #27ae60); )

Погледајте оловку а990б82465115ц2б556ф1б86бф4692ц7 аутора Хуга Гираудела (@ХугоГираудел) на ЦодеПен-у.