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

              
                
<div class="content">
  
  <p>Now days it's pretty common for progress or percentage bars to use a gradient from start to finish. <br> The problem I always encountered was that I wanted the gradient itself to represent progress. <br> Dark for low values (i.e. 10%, and light for higher values (i.e. 80%).</p>
  <p>Having said that, here is my approach to solving the problem. If you want to see a starker contrast, change <strong>$rose/$peach/$teal/$lime</strong> to more contrasting colors (black/white for example)</p>
  
  
  <section>
    <h2>Relative Gradient</h2>
    
    <b style="width: 10%;">applied gradient</b>
    <div class="progress">
      <span class="progress-bar cool" style="width: 10%;">
      </span>    
    </div>

    
   <b style="width: 50%;">applied gradient</b>
   <div class="progress">
      <span class="progress-bar cool" style="width: 50%;">
      </span>    
    </div>

    <b style="width: 95%;">applied gradient</b>
    <div class="progress">
      <span class="progress-bar cool" style="width: 95%;">
      </span>    
    </div>
  </section>
  
  
  <section>
    <h2>Absolute Gradient</h2>
    
    <b>applied gradient</b>
    <div class="health">
      <span class="progress-bar" style="width: 10%;">
        <span class="shade warm"></span>
      </span>    
    </div>

    <b>applied gradient</b>
    <div class="health">
      <span class="progress-bar" style="width: 50%;">
        <span class="shade warm"></span>
      </span>    
    </div>

    <b>applied gradient</b>
    <div class="health">
      <span class="progress-bar" style="width: 95%;">
        <span class="shade warm"></span>
      </span>    
    </div>
  </section>
  
</div>
              
            
!

CSS

              
                @import url(https://fonts.googleapis.com/css?family=Duru+Sans|Architects+Daughter);

$bar-height: 14px;
$bg: #393943;
$bg-darker: darken($bg, 8%);

$font-med: lighten($bg, 15%);
$font-light: lighten($bg, 30%);
$font-lighter: lighten($bg, 40%);

$button-size: $bar-height - 8;
$button-offset: #{4}px;
  
* {
  -moz-box-sizing: border-box;
  box-sizing: border-box;
}

body {
  background-color: $bg;
  font-family: "Duru Sans";
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-size: 100%;
  line-height: 1.6;
  color: $font-light;
}

.content {
  overflow: hidden;
  display: block;
  width: 900px;
  margin: 0 auto;
  padding-bottom: 100px;
}

section {
  width: 400px;
  display: block;
  margin: 0 auto;
  padding: 10px 0;
  float: left;
  margin-right: 100px;
  &:last-child {
    margin-right: 0;
  }
}



/*
 * GRADIENT BAR LINE STYLING
 */
.health, .progress {
  height: $bar-height + 1;
  width: 100%;
  margin-bottom: 30px;
  padding-top: 1px;
  border-radius: $bar-height / 2;
  background-color: $bg-darker;
  border-bottom: 1px solid #1f1f21;
  box-shadow: inset 0 2px 5px rgba(0,0,0,.3), 0 1px 0 rgba(255,255,255,.1);
  position: relative;
  .progress-bar {
      display: block;
      overflow: hidden;
      position: relative;
      height: 100%;
      margin-left: 1px;
      border-radius: $bar-height / 2;
      min-width: 13px;
      &:after {
        content: "";
        display: block;
        position: absolute;
        background-color: rgba(0,0,0,.2);
        width: $button-size;
        height: $button-size;
        top: $button-offset;
        right: 4px;
        border-radius: $button-size / 2;
        box-shadow: inset 0 2px 2px rgba(0,0,0,.3), 0 1px 1px rgba(255,255,255,.5);
      }
   }
}

.health .shade {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: block;
}

// Bar color schemes
$rose: #e83d89;
$peach: #ffa894;

$teal: #67cecd;
$lime: #eaef91;

.warm {
    background: $rose;
    background: -moz-linear-gradient(left,  $rose 30%, $peach 100%);
    background: -webkit-gradient(linear, left top, right top, color-stop(30%,$rose), color-stop(100%,$peach));
    background: -webkit-linear-gradient(left,  $rose 30%,$peach 100%);
    background: -o-linear-gradient(left,  $rose 30%,$peach 100%);
    background: -ms-linear-gradient(left,  $rose 30%,$peach 100%);
    background: linear-gradient(to right,  $rose 30%,$peach 100%);
    filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#67cecd', endColorstr='#eaef91',GradientType=1 );

    box-shadow: inset 0 1px 0 rgba(255,255,255,.3)
                ,inset 0 -3px 4px rgba(darken($rose, 10%),.4);
}

.cool {
    background: $teal;
    background: -moz-linear-gradient(left,  $teal 30%, $lime 100%);
    background: -webkit-gradient(linear, left top, right top, color-stop(30%,$teal), color-stop(100%,$lime));
    background: -webkit-linear-gradient(left,  $teal 30%,$lime 100%);
    background: -o-linear-gradient(left,  $teal 30%,$peach 100%);
    background: -ms-linear-gradient(left,  $teal 30%,$lime 100%);
    background: linear-gradient(to right,  $teal 30%,$lime 100%);
    filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#67cecd', endColorstr='#eaef91',GradientType=1 );

    box-shadow: inset 0 1px 0 rgba(255,255,255,.5)
                , inset 0 -3px 4px rgba(lighten($teal, 10%), .4);
}

/*
 * END GRADIENT BAR STYLING
 */

// Everything below here is just for the presentation format
p {
  font-size: .8rem;
}

h2 {
  font-family: "Architects Daughter";
  font-size: 1.5rem;
  color: $font-lighter;
  display: block;
  text-align: center;
}

b {
  font-weight: 400;
  font-family: "Architects Daughter";
  text-overflow: ellipsis;
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-align: center;
  margin-bottom: 10px;
  padding: 0 10px 6px 10px;
  font-size: .8rem;
  line-height: .8;
  
  position: relative;
  &:before, &:after {
    content: "";
    display: block;
    position: absolute;
    width: 1px;
    height: 100%;
    background-color: $font-med;
    top: 0;
  }
  &:before {
    left: 0;
  }
  &:after {
    right: 0;
  }
}

.content > p {
  text-align: center;
}
              
            
!

JS

              
                /*
 * TODO - I really wanted to be able to do the absolute bar without using JS, 
 * but haven't figured out a way to assign the width through just CSS. If anyone can
 * comeup with a way to get the same effect definitely let me know or just fork and fix.
 *
 * The design below also has a percentage tooltip. This can probably be done in the absolute
 * version, but would need an extra wrapper since the "bar" is overflow hidden.
 *
 * Design for the bars came from the wonderful dribbble shot by Daryl Ginn
 * http://dribbble.com/shots/169252-Percentage-Bar?list=following
 */

$barWidth = $('.health').width();
$('.shade').css('width', $barWidth);
              
            
!
999px

Console