cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

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.

Quick-add: + add another resource

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.

Quick-add: + add another resource

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.

            
              <h1>Let's Make A Performance Budget!</h1>

<div class="b">
  <div class="b-header">
    <h2 class="b-title" contenteditable>Template Name</h2>
    <em class="b-size">Budget: <span contenteditable>800</span>KB</em>
  </div><!--end b-header-->
  <div class="b-budget">
    <div class="b-cat-container">
      <em class="actual-size">Actual: <span>60</span>KB</em>
      <ul class="b-cat-list">
        <li class="b-cat b-cat-html">
          <label for="html">HTML</label>
          <input id="html" type="number" pattern="[0-9]*" value="50" />
        </li>
        <li class="b-cat b-cat-css">
          <label for="css">CSS</label>
          <input id="css" type="number" pattern="[0-9]*" value="100" />
        </li>
        <li class="b-cat b-cat-js">
          <label for="js">JS</label>
          <input id="js" type="number" pattern="[0-9]*" value="200" />
        </li>
        <li class="b-cat b-cat-img">
          <label for="img">Images</label>
          <input id="img" type="number" pattern="[0-9]*" value="200" />
        </li>
        <li class="b-cat b-cat-fonts">
          <label for="fonts">Fonts</label>
          <input id="fonts" type="number" pattern="[0-9]*" value="100" />
        </li>
        <li class="b-cat b-cat-ads">
          <label for="ads">Ads</label>
          <input id="ads" type="number" pattern="[0-9]*" value="50" />
        </li>
      </ul><!--end b-bar-->
    </div><!--end cat-container-->
  </div><!--end b-budget-->
</div><!--end b-->
<button class="btn">Add new template</button>

<footer role="contentinfo">
  <a href="http://bradfrost.com/blog/post/performance-budget-builder/" target="_blank">More info on this project</a>. Made by <a href="http://bradfrost.com">Brad Frost</a> (<a href="https://twitter.com/brad_frost">@brad_frost</a>)
</footer>
            
          
!
            
              * {
  box-sizing: border-box;  
}

body {
  font-family: 'Open Sans', sans-serif;
  padding: 1.2em;
  background: #f8f4e6;
}

input[type=number] {
  -moz-appearance:textfield;
}

input[type=number]::-webkit-inner-spin-button, 
input[type=number]::-webkit-outer-spin-button { 
  -webkit-appearance: none;
  -moz-appearance:textfield;
  margin: 0; 
}

[contenteditable] {
  border-bottom: 1px dotted #EF944D;
}

h1 {
  text-align: center;
  font-size: 2em;
  margin-bottom: 2em;
  color: #d5c9a5;
}

.b {
  margin-bottom: 4em;
}

.b-header {
  position: relative;
  padding-bottom: 0.5rem;
  display: flex;
}

.b-size {
  position: absolute;
  top: -1rem;
  right: 0;
  display: block;
  padding: 0 0.5rem 3rem 0;
  border-right: 1px dashed #d5c9a5;
  font-size: 80%;
  font-style: normal;
  font-weight: bold;
  color: #999;
}

.b-title {
  display: inline-block;
  margin: 0 0.2em;
  line-height: 1;
}

.b-budget {
  background: #eee;
  background: repeating-linear-gradient(
  45deg,
  #e9e9e9,
  #e9e9e9 10px,
  #f0f0f0 10px,
  #f0f0f0 20px
);
  border-radius: 1em;
  box-shadow: 8px 8px 0 rgba(0,0,0,0.08);
}

.b-cat-container {
  min-width: 210px !important;
  transition: width 0.3s ease-in-out;
  position: relative;
}

.actual-size {
  position: absolute;
  top: -1.5rem;
  right: 0;
  display: block;
  padding: 0 0.5rem 1rem 0;
  border-right: 1px dashed #d5c9a5;
  font-size: 80%;
  font-style: normal;
  font-weight: bold;
  color: #d5c9a5;
}

.b-cat-list {
  list-style: none;
  padding: 0;
  margin: 0 0 2em;
  display: flex;
  align-items: center;
  border-radius: 1em;
  overflow: hidden;
}

//Budget Category
.b-cat {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  min-width: 35px !important;
  width: 100%;
  font-weight: bold;
  color: rgba(0,0,0,0.5);
  transition: width 0.3s ease-in-out;
  
  label {
    padding-top: 1rem;
    font-size: 80%;
    display: block;
    width: 100%;
    text-align: center;
  }
  
  input {
    display: block;
    border: 0;
    background: none;
    color: rgba(0,0,0,0.5);
    text-align: center;
    font-weight: bold;
    font-size: 1.3em;
    width: 100%;
    padding-bottom: 1rem;
    outline: 0;
    transition: background 0.1s ease-in-out;
    
    &:focus {
      background: rgba(0,0,0,0.1);
    }
  }
  
  &-html {
    background: #37393A;
    color: rgba(255,255,255,0.6);
    
    input {
      color: rgba(255,255,255,0.6);
    }
  }
  
  &-css {
    background: #F9ECC5;
  }
  
  &-js {
    background: #EF944D;
  }
  
  &-img {
    background: #EBC050;
  }
  
  &-fonts {
    background: #598FC2;
  }
  
  &-ads {
    background: #777;
    color: rgba(255,255,255,0.7);
    
    input {
      color: rgba(255,255,255,0.7);
    }
  }
}

//Button
.btn {
  font-weight: bold;
  text-transform: uppercase;
  border: 0;
  display: block;
  padding: 2em;
  margin: 0 auto 4em;
  background: #ccc;
  border-radius: 1em;
  box-shadow: 8px 8px 0 rgba(0,0,0,0.08);
  cursor: pointer;
  transition: background 0.2s ease-in-out;
  
  &:hover, &:focus {
    background: #bbb;
  }
}

.has-error {
  color: #a92101;
  animation: shake 0.82s cubic-bezier(.36,.07,.19,.97) both;
  transform: translate3d(0, 0, 0);
  backface-visibility: hidden;
  perspective: 1000px;

  em {
    color: inherit;
  }
}

footer {
  margin-top: 4em;
  color: #d5c9a5;
  text-align: center;
  
  a {
    color: #d5c9a5;
    
    &:hover, &:focus {
      color: #EF944D;
    }
  }
}

@keyframes shake {
  10%, 90% {
    transform: translate3d(-1px, 0, 0);
  }
  
  20%, 80% {
    transform: translate3d(2px, 0, 0);
  }

  30%, 50%, 70% {
    transform: translate3d(-4px, 0, 0);
  }

  40%, 60% {
    transform: translate3d(4px, 0, 0);
  }
}
            
          
!
            
              //On input keyup
$('body').on('keyup', '.b-cat input', function(){
  var $this = $(this),
      val = parseInt($this.val());
  
  //Set widths of categories
  setCatWidths($this.parents('.b'));
  
  calculateActualSize($(this).parents('.b'));
});

//Set width of category
function setCatWidths(scope) {
  scope.find('.b-cat input').each(function(){
     var $this = $(this),
         val = parseInt($this.val());
    $this.parent().width(calculateCatWidth(scope,val)+'%');
  });
}

setCatWidths($('.b'));

//Adjust budget value
$('body').on('keyup', '.b-size span', function(){
  
  //Check if actual size is over/under budget
  budgetOverUnder($(this).parents('.b')); 
});

//Calculate Actual Template Size
function calculateActualSize(scope) {
  var inputs = $('.b-cat input'),
      numInputs = inputs.length,
      totalActualSize = 0;
  
  //Calculate total value from each category
  scope.find('.b-cat input').each(function(){
     var val = parseInt($(this).val());
     totalActualSize = totalActualSize + val;
  });
  
  setActualSize(scope,totalActualSize);
  
  //Check if actual size is over/under budget
  budgetOverUnder(scope); 
}

calculateActualSize($('.b'));

//Calculate width
function calculateCatWidth(scope,val) {
  var actualSize = parseInt(scope.find('.actual-size span').text());
  console.log(actualSize);
  var categoryWidth = (val/actualSize)*100;
  return categoryWidth;
}

//Set Actual Size
function setActualSize(scope,val) {
  actualSize = val;
  scope.find('.actual-size span').text(val);
}

//Determine if actual size is within budget
function budgetOverUnder(scope) {
  var budgetSize = parseInt(scope.find('.b-size span').text());
  var actualSize = parseInt(scope.find('.actual-size span').text());
  var totalSize = actualSize/budgetSize;
  
  //If actual val is over budget
  if(totalSize>1) {
    scope.find('.b-header, .actual-size').addClass('has-error');
   scope.find('.b-cat-container').width('100%');
  } else {
    scope.find('.b-header, .actual-size').removeClass('has-error');
    scope.find('.b-cat-container').width(totalSize*100+'%');
  }
}

budgetOverUnder($('.b'));

//Make new Budget
$('.btn').on('click', function(){
  $('.b').last().clone().insertBefore('.btn');
});
            
          
!
999px
Loading ..................

Console