css - How can I make my Sass Mixin DRY-er? -


i have created several mixins buttons attempt reduce duplication , contribute overall improvement of performance. looking guidance on how tighten dry (don't repeat yourself) possible. or dry possible? thank thoughts. here code:

// mixin - button shape @mixin buttonshape {     vertical-align:middle;     line-height:1.333rem;height:2.166rem;     color:#282a2e;     border-radius:0;     margin-top:1.083rem;     margin-bottom:.333rem;     margin-right:1.073rem;     border:none;     transition: background-color .2s; }  // mixin - button gradients @mixin gradientnormal {     background-color:#efefee;     background:linear-gradient(to bottom,#efefee 0,#d0d0ce 100%);     box-shadow:inset 0 0 0 .083rem #fff;outline:1px solid silver; }  @mixin gradienthoveractive {     background:linear-gradient(to bottom,#ffffff 0,#ffffff 100%);     box-shadow:inset 0 0 0 .083rem #fff;outline:2px solid #e87722; }   // normal state .ui-widget-header .ui-button, .ui-widget-content .ui-button, .ui-button {     font-size: 12px;     @include buttonshape;     @include gradientnormal; }  // hover .ui-widget-header .ui-button:enabled:hover, .ui-widget-header .ui-button:focus, .ui-widget-content .ui-button:enabled:hover, .ui-widget-content .ui-button:focus, .ui-button:enabled:hover, .ui-button:focus {     @include buttonshape;     @include gradienthoveractive; }  // active .ui-widget-header .ui-button:enabled:active, .ui-widget-content .ui-button:enabled:active, .ui-button:enabled:active {     @include buttonshape;     @include gradienthoveractive; } 

first, font-size: 12px referenced selectors include gradientnormal, makes sense move there.

you can combine active , hover states one, have same includes:

// mixin - button shape @mixin buttonshape {     vertical-align:middle;     line-height:1.333rem;     height:2.166rem;     color:#282a2e;     border-radius:0;     margin-top:1.083rem;     margin-bottom:.333rem;     margin-right:1.073rem;     border:none;     transition: background-color .2s; }  // mixin - button gradients @mixin gradientnormal {     background-color:#efefee;     background:linear-gradient(to bottom,#efefee 0,#d0d0ce 100%);     box-shadow:inset 0 0 0 .083rem #fff;     outline:1px solid silver;     font-size: 12px; }  @mixin gradienthoveractive {     background:linear-gradient(to bottom,#ffffff 0,#ffffff 100%);     box-shadow:inset 0 0 0 .083rem #fff;     outline:2px solid #e87722; }  // normal state .ui-widget-header .ui-button, .ui-widget-content .ui-button, .ui-button {     @include buttonshape;     @include gradientnormal; }  // hover & active .ui-widget-header .ui-button:enabled:hover, .ui-widget-header .ui-button:focus, .ui-widget-content .ui-button:enabled:hover, .ui-widget-content .ui-button:focus, .ui-button:enabled:hover, .ui-button:focus, .ui-widget-header .ui-button:enabled:active, .ui-widget-content .ui-button:enabled:active, .ui-button:enabled:active {     @include buttonshape;     @include gradienthoveractive; } 

you separate out selectors based on gradient use, considering @include buttonshape referenced 3 states, though result in larger total number of lines.

hope helps! :)


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -