Making multiple gradients using Less CSS -


this first project i've used less on, want make series of buttons have same general structure have different gradiated colours applied them.

i have default button style:

.button-regular (@origin: top, @start: #d2d2d2, @middle: #7a7a7a, @stop: #4d4d4d, @fallback: #3f4c6b, @border: #3c3c3c;) {   border-radius: 3px; color: @white; font-size: 13px; line-height: 18px; height: 36px; font-weight: normal; padding: 8px 15px 8px 15px; text-align: center;   background: @fallback;   background: -moz-linear-gradient(@origin, @start 0%, @middle 6%, @stop 100%);   background: -webkit-gradient(linear, left top, left bottom, color-stop(0%, @start), color-stop(6%, @middle), color-stop(100%, @stop));   background: -webkit-linear-gradient(@origin, @start 0%, @middle 6%, @stop 100%);   background: -o-linear-gradient(@origin, @start 0%, @middle 6%, @stop 100%);   background: -ms-linear-gradient(@origin, @start 0%, @middle 6%, @stop 100%);   background: linear-gradient(to bottom, @start 0%, @middle 6%, @stop 100%);   filter: progid:dximagetransform.microsoft.gradient(startcolorstr='@middle', endcolorstr='@stop', gradienttype=0);   border: 1px solid @border; } 

i want overwrite colours each new instance of button using below:

input.lightblue {   .button-regular(top, #bfeef8, #40cdeb, #00bce4, #3f4c6b, #00b0d5;); }  

but when create button:

<input class="lightblue" type="submit" value="search"> 

the original (grey) colours still show. there reason why colours aren't overwritten using new colours in new button instance, , there better way acheive i'm attempting?

i'm using less.js compile in-browser if makes difference.

what have there should work alright, need to

fix typo:

  • there semicolon (;) (after last color) in class definition

    input.lightblue {   .button-regular (top, #bfeef8, #40cdeb, #00bce4, #3f4c6b, #00b0d5); } 
  • you call variable @white in mixin, need make sure define beforehand, or else write white instead.

some additional suggestions:

(i used random settings illustration). this

<input class="button default" type="submit" value="search"> <input class="button green" type="submit" value="search"> <input class="button red" type="submit" value="search"> 

where have button class define general button appearance. dunno, maybe this:

.button {     display: inline-block;     outline: none;     cursor: pointer;     text-align: center;     text-decoration: none;     font: 14px/100% arial, helvetica, sans-serif;     padding: .5em 2em .55em;     text-shadow: 0 1px 1px rgba(0,0,0,.3);      -webkit-box-shadow: 0 1px 2px rgba(0,0,0,.2);     -moz-box-shadow: 0 1px 2px rgba(0,0,0,.2);     box-shadow: 0 1px 2px rgba(0,0,0,.2); } .button:active {     position: relative;     top: 1px; } 

and in less make mixins color gradients. this:

.gradient-mixin (@origin, @start, @middle, @stop, @fallback, @border) {   background: @fallback;   background: -moz-linear-gradient(@origin, @start 0%, @middle 6%, @stop 100%);   background: -webkit-gradient(linear, left top, left bottom, color-stop(0%, @start), color-stop(6%, @middle), color-stop(100%, @stop));   background: -webkit-linear-gradient(@origin, @start 0%, @middle 6%, @stop 100%);   background: -o-linear-gradient(@origin, @start 0%, @middle 6%, @stop 100%);   background: -ms-linear-gradient(@origin, @start 0%, @middle 6%, @stop 100%);   background: linear-gradient(to bottom, @start 0%, @middle 6%, @stop 100%);   filter: progid:dximagetransform.microsoft.gradient(startcolorstr='@middle', endcolorstr='@stop', gradienttype=0);   border: 1px solid @border; }  .button-make (@name:"default", @origin: top, @start: #d2d2d2, @middle: #7a7a7a, @stop: #4d4d4d, @fallback: #3f4c6b, @border: #3c3c3c;) {   @classname: ~"@{name}";   .@{classname} {     .gradient-mixin (@origin, @start, @middle, @stop, @fallback, @border);     &:hover {     .gradient-mixin(@origin, lighten(@start,10%), lighten(@middle,10%), lighten(@stop,10%), lighten(@fallback,10%), @border);     }     &:active {     .gradient-mixin (@origin, darken(@start,10%), darken(@middle,10%), darken(@stop,10%), darken(@fallback,10%), @border);     }   } } 

and call them each color ... build classes each color buttons:

.button-make; .button-make ("green", top, #7db72f, #87d918, #4e7d0e, #7db72f, #538312); .button-make ("red", top, #ed1c24, #e93a3f, #aa1317, #ed1c24, #980c10); 

here jsfiddle example of output.

but instead of defining colors in gradient hand can make more general mixin in less, takes 1 color , transforms colors use @stop,@start,@border,... using lighten, darken , other color operations.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

javascript - Clean way to programmatically use CSS transitions from JS? -

android - send complex objects as post php java -