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 CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

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.

            
              @import 'https://fonts.googleapis.com/css?family=Lato|Roboto+Slab|Share+Tech+Mono';

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

@-webkit-keyframes bgAnimate {
  0% { background-position: 0% 50% }
  50% { background-position: 100% 50% }
  100% { background-position: 0% 50% }
}

@-moz-keyframes bgAnimate {
  0% { background-position: 0% 50% }
  50% { background-position: 100% 50% }
  100% { background-position: 0% 50% }
}

@keyframes bgAnimate {
  0% { background-position: 0% 50% }
  50% { background-position: 100% 50% }
  100% { background-position: 0% 50% }
}

body {
  background: linear-gradient(238deg, #c37a25, #ebf0a7, #ee3e3e, #803eee, #3eee9a);
  background-size: 1000% 1000%;
  -webkit-animation: bgAnimate 30s ease infinite;
  -moz-animation: bgAnimate 30s ease infinite;
  animation: bgAnimate 30s ease infinite;
  font-family: 'Lato', sans-serif;
}

h1 {
  text-align: center;
  font-size: 28px;
  color: #fff;
  width: 300px;
  margin: 20px auto;
  font-family: 'Roboto Slab', serif;
}

.lyrics {
  padding: 5px;
  width: 450px;
  background: white;
  margin: 30px auto 0;
  -webkit-box-shadow: 0 0 8px rgba(#000, 0.3);
  -moz-box-shadow: 0 0 8px rgba(#000, 0.3);
  box-shadow: 0 0 8px rgba(#000, 0.3);
  -webkit-border-radius: 3px;
  -moz-border-radius: 3px;
  border-radius: 3px;
  
  p {
    margin: 0 0 3px;
    padding: 8px 15px;
    color: #666;
    
    &:before, &:after {
      content: " ";
      display: table;
    }
    
    &:after {
      clear: both;
    }
    
    &:nth-child(odd) {
      background: #f9f9f9;
    }
    
    span {
      display: block;
      float: left;
      
      &:nth-child(1) {
        color: #222;
        padding-right: 16px;
        width: 50%;
      }
      
      &:nth-child(2) {
        width: 10%;
        color: #ccc;
      }
      
      &:nth-child(3) {
        font-family: 'Share Tech Mono', monospace;
        width: 40%;
      }
    }
  }
}
            
          
!
            
              
/**
 * This function is used to create a sluged version of a string.
 * This is very useful when you want to prepare a key for a JSON object, for
 * example.
 */
function slug(string, delimiter) {
  // Check to see if we passed a delimiter or not. We default
  // to using the underscore when one is not present
  delimiter = delimiter || '_';
  
  return string
    // Adds a space between letters when the string is camelCased
    .replace(/([a-z])([A-Z])/g, '$1 $2')
  
    // Make the string lower case, removing camel case
    .toLowerCase()
  
    // Remove special characters (also only alows lowercase) 
    // and replace them with the delimiter. This forces it to only allow
    // letters and numbers
    .replace(/[^a-z0-9]+/g, delimiter)
  
    // removes the trailing delimiter, in case one gets added
    .replace(new RegExp('^' + delimiter + '|' + delimiter + '$', 'g'), '');
}

var lyrics = [
  'HelloFrom',
  'TheOTHER_Side',
  'I must have CALLED',
  'A -Th*&ousand()times',
  'ToTell',
  'y---ou',
  'I\'m sorRy',
  'forEverthing',
  'ThatI\'ve DONE',
  'But when I call',
  'you never',
  'seemToBeHome'
];

var html = '<h1>Creating slugs with JavaScript</h1><div class="lyrics">';

for ( var i = 0; i < lyrics.length; i++) {
  html += '<p>';
  html += '<span>' + lyrics[i]+ '</span>';
  html += '<span class="fa fa-arrow-right" aria-hidden="true"></span>';
  html += '<span>' + slug(lyrics[i]) + '</span>';
  html += '</p>';
}

html += '</div>';

document.body.innerHTML = html;
            
          
!
999px
Loading ..................

Console