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 is required to process package imports. If you need a different preprocessor remove all packages first.

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

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

              
                h1 Random Colors of Imagination
    button#random(class='button') Randomize
    button#shadow(class='button') Box-shadow

section.main
    - for (i = 0; i < 500; i++) {
      div.box
    - }
    
footer.attr
    p A pen by <a href='http://stramaxon.com' target='_blank'>Deepak Kamat</a> <a href='https://twitter.com/xxxdepy'>@xxxdepy</a>
    p(style='color:#999;') Web Designer - Developer - Programmer
              
            
!

CSS

              
                h1 {
  font-size:1em;
  text-transform:uppercase;
  text-align:center;
  color:#666;
}

section.main {
  background-color:#eee;
}

.box {
  box-sizing:border-box;
  width:50px; height:50px;
  display:inline-block;
  
  margin:-2px 0;
  margin-right:-4px;
  
  background-color:#fff;
  transition:0.5s all ease-in-out;
  
  filter:hue-rotate(0deg);
  animation:hueRotate 0s linear infinite;
}

/* Box Shadow - simply add a class to the parent container. */
section.main.shadow .box {
  box-shadow: inset 1px 4px 6px rgba(0, 0, 0, 0.4);
}


.button {
  background-color:rgba(255, 47, 105, 0.82);
  color:#fff;
  border:none;
  padding:2px 8px;
  display:inline-block;
  border-radius:5px;
  
  z-index:1;
}

#random {
  position:fixed;
  left:20px;
  top:8px;
}

#shadow {
  position:fixed;
  top:8px;
  right:10px;
}

/* Footer style */
footer.attr {
  font-family:"Consolas", monospace;
  color:#444;
  
  padding:20px;
  text-align:center;
}

footer.attr a {
  color:rgba(255, 47, 105, 0.82);
}


/*
@keyframes hueRotate{
  from {
    filter:hue-rotate(0deg);
  }
  
  to {
    filter:hue-rotate(180deg);
  }
}
*/

              
            
!

JS

              
                $(document).ready(function(){
  random_box_color();
  
  $("#random").on('click', function(){
    random_box_color();
  });
  
  $("#shadow").on('click', function(){
    $('section.main').toggleClass('shadow');
  });
});


function random_box_color() {
  $('.box').each(function(e){
    var r = randomColor();
    var color = "rgb(" + r[0] + ", " + r[1] + ", " + r[2] + ")";
    
    $(this).css({"background-color": color});
  });
}

function randomColor() {
  var rgb_val = [];
  
  for (i = 0; i < 3; i++) {
    rgb_val.push(randInt(0, 255));
  }
  
  return rgb_val;
}

// For random integer
function randInt(min, max) {
    return Math.floor(Math.random() * (max - min + 1)) + min;
}
              
            
!
999px

Console