Pen Settings

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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <div id="buttons">
  <h1>Intro to SCSS: Buttons</h1>

  <p>The buttons below are each marked-up with a <code>.button</code> class, and one with <code>.cta</code>, one with <code>.secondary</code>class, and another with <code>.color-secondary</code>.</p>

  <p>If you view the SCSS window, you'll see how we can leverage SCSS <code>$variables</code>, <code>@functions</code>, <code>@mixins</code> to create the styling on these buttons.</p>

  <p>
    <a href="#" class="button">Primary</a>
    <a href="#" class="button cta">CTA</a>
    <a href="#" class="button secondary">Secondary</a>
    <a href="#" class="button color-secondary">Color change</a>
  </p>

  <p>For a few buttons, the <code>@functions</code> and <code>@mixins</code>  may seem like over-kill, but consider this:</p>

  <blockquote>
    <p>You have a <code>.button</code> class set and have every button across your site using that class. Things are awesome, everything looks great.</p>

    <p>What happens when you introduce a plugin and don't have access to add a class to the mark-up?</p>
  </blockquote>

  <p>One option is you could write out the selector and put it where you have the <code>.button</code> class defined.</p>

  <p>A lot of the time you're already styling different elements that this plugin has spit out for you, so option one isn't really ideal. The best thing to do at this point is <code>@include button</code> to keep all your styles for that plugin in one place</p>
</div>
            
          
!
            
              @import url(https://fonts.googleapis.com/css?family=Open+Sans:400,700,600);

/*
SCSS variables are always prefixed with $
*/

// Color Variables
$primary: #2876fc;
/*
complement is a built in function that accepts 1 argument for color.

The function will return a color that works well with the color provided.
*/
$secondary: complement($primary);
$light: #eee;
$dark: #222;

// Button variables
$btn-height: 30px;

/*
Functions will return information where it has been called

In the function below, text-color accepts one argument for color, determines how much lightness the color has, and then returns a light or dark color.

I use this to try and dynamically set the
font-color on an element based on it's
background-color.
*/
@function text-color( $color ) {
  @if ( lightness($color) > 50% ) {
    @return #111;
  } @else {
    @return #eee;
  }
}

/*
Mixins are resusable chunks of code that
accept arguments to dynamically control output.
*/
@mixin button ( $bkg: $primary, $color: text-color($bkg) ) {
  background: $bkg;
  color: $color;
  display: inline-block;
  line-height: $btn-height;
  opacity: 1;
  padding: 0 10px;
  text-shadow: 0 1px 1px darken($primary, 15%);
  transition: opacity 250ms;
  &:hover {
    opacity: .8;
  }
}

/*
cta-button is meant to be used in tandem with the button mixin. This mixin extends button by adding either a left or right arrow.

Because the CTA appends an arrow using a border, the background color will not inherit from the button. By default, the background-color for button and border-color for cta-button are set to $primary.
*/
@mixin cta-button ( $dir: right, $color: $primary ) {
  margin-#{$dir}: $btn-height/2;
  position: relative;

  &:before {
    content: '';

    border-bottom: $btn-height/2 solid transparent;
    border-top: $btn-height/2 solid transparent;

    position: absolute;
    bottom: 0;
    top: 0;

    @if ( $dir == right ) {
      border-left: $btn-height/2 solid $color;
      left: 100%;
    } @else {
      border-right: $btn-height/2 solid $color;
      right: 100%;
    }
  }
}

:root {
  background-color: $primary;
  color: $dark;
  font-family: 'Open Sans', Helvetica, sans-serif;
}

* {
  box-sizing: border-box;
  *,
  &:before,
  &:after {
    box-sizing: inherit;
  }
}

code {
  background: rgba(black, .1);
  padding: 0 4px;
}

#buttons {
  background: $light;
  /*
  darken() and lighten() are built functions
  that accept 2 arguments;
  color, percent 0% - 100%

  They will take the color and add/remove
  lightness by the percent passed
  */
  border: 5px solid darken($light, 10%);
  margin: 50px auto;
  max-width: 94%;
  width: 600px;
  padding: 20px;
  img {
    border-radius: 100%;
  }
}

.button {
  // To use a @mixin, you @include mixin-name
  @include button;

  &.cta {
    @include cta-button;
  }
  
  /*
  Typically if you wanted a button with a
  specific text color or background-color,
  you can just add another class and style
  for that difference.

  In a real world situation, this isn't the
  best way to set this style. This writes a
  mess of additional properties that you don't
  need, but it's a good example.
  
  With background-color being the first
  argument in the @mixin, you can change that
  by listing the color on it's own. If you want
  to explicity set background and color, you
  can comma separate the 2 arguments.
  */
  &.secondary {
    @include button($secondary);
  }
  
  /*
  If you want pass an argument but it's not in
  the order they're listed in the @mixin, you
  must find the name of the argument as written
  in the @mixin and set it by name.
  */
  &.color-secondary {
    @include button($color: $secondary);
  }
}
            
          
!
            
              $('body').on('click', '#buttons .button', function () {
  return false;
} );
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.

Console