Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                .container
  %h1 Bootstrap Custom Button SCSS Mixin
  %p
    This mixin is a shortcut to create a bootstrap button in any color. It adjusts the border and text colors to work well with the given color, then uses Bootstrap's
    %code button-variant
    mixin to do the styling.

  %h3 Social buttons
  .btn-group
    %a.btn.btn-facebook
      %i.fa.fa-facebook.btn-icon
      Like
    %a.btn.btn-twitter
      %i.fa.fa-twitter.btn-icon
      Tweet
    %a.btn.btn-google-plus
      %i.fa.fa-google-plus.btn-icon
      Share
    %a.btn.btn-pinterest
      %i.fa.fa-pinterest.btn-icon
      Pin
  %h3 Gray buttons
  .btn-group
    %a.btn.btn-0 #000
    %a.btn.btn-1 #111
    %a.btn.btn-2 #222
    %a.btn.btn-3 #333
    %a.btn.btn-4 #444
    %a.btn.btn-5 #555
    %a.btn.btn-6 #666
    %a.btn.btn-7 #777
    %a.btn.btn-8 #888
    %a.btn.btn-9 #999
    %a.btn.btn-a #aaa
    %a.btn.btn-b #bbb
    %a.btn.btn-c #ccc
    %a.btn.btn-d #ddd
    %a.btn.btn-e #eee
    %a.btn.btn-f #fff
  %h3 Random colored buttons
  #random-btn-group.btn-group
    %a.btn.btn-random-1
    %a.btn.btn-random-2
    %a.btn.btn-random-3
    %a.btn.btn-random-4
    %a.btn.btn-random-5
    %a.btn.btn-random-6
    %a.btn.btn-random-7
    %a.btn.btn-random-8
    %a.btn.btn-random-9
    %a.btn.btn-random-10
  %h2 How to use the mixin
  %p
    First add Bootstrap's
    %code button-variant
    mixin that can be found on their
    %a(href="https://github.com/twbs/bootstrap-sass/blob/master/assets/stylesheets/bootstrap/mixins/_buttons.scss") Github repository
    to your scss file and then my
    %code bootstrap-button
    mixin after that.
  %pre.scss
    %code
      :preserve
        @mixin bootstrap-button($background) {
          $color: #fff;
          $border: 5%;
          @if (lightness($background) >= lightness(#aaa)) {
            $color: #333;
            $border: .2 * lightness($background);
          }
          @include button-variant($color, $background, darken($background, $border));
        }
  %p
    After adding the mixins, then include my mixin with your custom color, and it will style any
    %code &lt;button&gt;
    or
    %code &lt;a&gt;
    elements with that class.
  %pre.scss
    %code
      :preserve
        .btn-helloworld {
          @include bootstrap-button(#3566e7);
        }
  %pre.html
    %code
      :escaped
        <button class="btn btn-helloworld">Hello World</button>
  %a.btn.btn-helloworld Hello World

              
            
!

CSS

              
                // Bootstrap 3.3.5 mixin required by my mixin
// bootstrap-sass/assets/stylesheets/bootstrap/mixins/_buttons.scss
@mixin button-variant($color, $background, $border) {
  color: $color;
  background-color: $background;
  border-color: $border;
  &:focus, &.focus {
    color: $color;
    background-color: darken($background, 10%);
    border-color: darken($border, 25%);
  }
  &:hover {
    color: $color;
    background-color: darken($background, 10%);
    border-color: darken($border, 12%);
  }
  &:active, &.active, .open > &.dropdown-toggle {
    color: $color;
    background-color: darken($background, 10%);
    border-color: darken($border, 12%);

    &:hover, &:focus, &.focus {
      color: $color;
      background-color: darken($background, 17%);
      border-color: darken($border, 25%);
    }
  }
  &:active, &.active, .open > &.dropdown-toggle {
    background-image: none;
  }
  &.disabled, &[disabled], fieldset[disabled] & {
    &, &:hover, &:focus, &.focus, &:active, &.active {
      background-color: $background;
      border-color: $border;
    }
  }
  .badge {
    color: $background;
    background-color: $color;
  }
}

// Mixin to create a bootstrap button with custom colors
@mixin bootstrap-button($background) {
  $color: #fff;
  $border: 5%;
  @if (lightness($background) >= lightness(#aaa)) {
    $color: #333;
    $border: .2 * lightness($background);
  }
  @include button-variant($color, $background, darken($background, $border));
}

// Social buttons
.btn-facebook    { @include bootstrap-button(#3b5999); }
.btn-twitter     { @include bootstrap-button(#55acee); }
.btn-google-plus { @include bootstrap-button(#df4a32); }
.btn-pinterest   { @include bootstrap-button(#cc2127); }

// Gray buttons
.btn-0 { @include bootstrap-button(#000); }
.btn-1 { @include bootstrap-button(#111); }
.btn-2 { @include bootstrap-button(#222); }
.btn-3 { @include bootstrap-button(#333); }
.btn-4 { @include bootstrap-button(#444); }
.btn-5 { @include bootstrap-button(#555); }
.btn-6 { @include bootstrap-button(#666); }
.btn-7 { @include bootstrap-button(#777); }
.btn-8 { @include bootstrap-button(#888); }
.btn-9 { @include bootstrap-button(#999); }
.btn-a { @include bootstrap-button(#aaa); }
.btn-b { @include bootstrap-button(#bbb); }
.btn-c { @include bootstrap-button(#ccc); }
.btn-d { @include bootstrap-button(#ddd); }
.btn-e { @include bootstrap-button(#eee); }
.btn-f { @include bootstrap-button(#fff); }

// Random colored buttons
@for $i from 1 through 10 {
  .btn-random-#{$i} {
    $color: rgb(random(255), random(255), random(255));
    @include bootstrap-button($color);
    &::after {
      content: "#{$color}";
    }
  }
}

.btn-helloworld { @include bootstrap-button(#3566e7); }

              
            
!

JS

              
                hljs.initHighlightingOnLoad(); // Highlight the code sample

              
            
!
999px

Console