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

              
                <main id = "root">
    <article class = "f v h c">
      <section class = "f v h">
        
        <section class = "f v h r">
          <section class = "container" id = "c1"></section><div class = "icon"><img src = "https://semicolon.dev/static/comment.png" /></div>
        </section>

        <section style = "width: 25px"></section>
        
        <section class = "f v h r">
          <section class = "container" id = "c2"></section><div class = "icon"><img src = "https://semicolon.dev/static/love.png" /></div>
        </section>

        <section style = "width: 25px"></section>

        <section class = "f v h r">
          <section class = "container" id = "c3"></section><div class = "icon"><img src = "https://semicolon.dev/static/retweet.png" /></div>
        </section>

      </section>

      <section class = "f v h r">
        <div class = "f c">
          <button id = "bc1">+1 comment</button>
          <button id = "bc10">+10 comment</button>
          <button id = "bc100">+100 comment</button>
        </div>
        <div class = "f c">
          <button id = "bl1">+1 like</button>
          <button id = "bl10">+10 like</button>
          <button id = "bl100">+100 like</button>
        </div>
        <div class = "f c">
          <button id = "br1">+1 retweet</button>
          <button id = "br10">+10 retweet</button>
          <button id = "br100">+100 retweet</button>
        </div>
      </section>

    </article>
  </main>
              
            
!

CSS

              
                
    button { margin: 8px }

    body {

    }

    #root {

    }

    main {
      height: 100%;
    }

    * { font-family: Arial; }

    /* padding shouldn't impact element width this is also CSS grid's default setting */
    * { box-sizing: border-box }

    .noselect {
  -webkit-touch-callout: none; /* iOS Safari */
    -webkit-user-select: none; /* Safari */
     -khtml-user-select: none; /* Konqueror HTML */
       -moz-user-select: none; /* Old versions of Firefox */
        -ms-user-select: none; /* Internet Explorer/Edge */
            user-select: none; /* Non-prefixed version, currently
                                  supported by Chrome, Edge, Opera and Firefox */
   }

    /* vertical and horizontal align */
.f { display: flex }
.v { align-items: center }
.vs { align-items: flex-start }
.ve { align-items: flex-end }
.h { justify-content: center }
.hs { justify-content: flex-start }
.he { justify-content: flex-end }
.r { flex-direction: row }
.c { flex-direction: column }
.s { justify-content: space-around }
    .o { padding: 5px }
    .p { padding: 10px }
    .pp { padding: 20px }
    .ppp { padding: 30px }
    .m { margin: 5px }
    .mm { margin: 10px }
    .mmm { margin: 20px }
    .mmmm { margin: 30px }
    .b { font-size: 28px }
    .abs { position: absolute }
    .rel { position: relative }

    /* Chrome applies blue "usability" background  to autofilled input boxes, but it's a nightmare for custom design */
    input:-webkit-autofill, input:-webkit-autofill:hover, input:-webkit-autofill:focus, input:-webkit-autofill:active { -webkit-box-shadow: 0 0 0 30px white inset !important }

    /* Remove Chrome outline (same reason as above) */
    *:focus { outline: none }

    /* Mobile first, means this media query first -- use min-width in ascending order
    Smallest phone screen (iphone, android, etc.) */
    @media screen and (min-width: 600px) {
    * {  }
    }

    /* Next wider view (iphone pro, etc) */
    @media screen and (min-width: 800px) {
      * {  }
    }

    /* Next wider view (tablets) */
    @media screen and (min-width: 1000px) {
      * {  }
    }

    /* Full screen desktop */
    @media screen and (min-width: 1200px) {
      * {  }
    }
    
    /* Reasonably decent font */
    * {
      font-family: Arial;
    }

.container { /* digit container */
  overflow: hidden;     
  height: 24px;      
  display: flex;
  position: relative;      
}

.animate { max-width: 10px; transition: 0.4s }
.digit { font-weight: bold; border: 0 !important }

/* animation offsets */
.offset-0 { margin-top: 4px }
.offset-1 { margin-top: -14px }
.offset-2 { margin-top: -32px }
.offset-3 { margin-top: -50px }
.offset-4 { margin-top: -68px }
.offset-5 { margin-top: -86px }
.offset-6 { margin-top: -104px }
.offset-7 { margin-top: -122px }
.offset-8 { margin-top: -140px }
.offset-9 { margin-top: -158px }
.offset-10 { margin-top: -176px }
.offset-11 { margin-top: -170px }
.offset-12 { margin-top: -288px }
.offset-13 { margin-top: -212px } /* dot */
.offset-14 { margin-top: -232px } /* space */
    
    .icon img { margin-right: 3px; transform: scale(0.80) }

    body {
      margin-top: 40px;
    }
              
            
!

JS

              
                // Use $ and $$ instead of dinosauric document.querySelector function
let $ = selector => document.querySelector(selector);
let $$ = selector => document.querySelectorAll(selector);

// Map characters to CSS offsets
const mapping = {
  '0':0,
  '1':1,
  '2':2,
  '3':3,
  '4':4,
  '5':5,
  '6':6,
  '7':7,
  '8':8,
  '9':9,
  'K':10,
  'M':11,
  'B':12,
  '.':13,
  ' ':14,
}

const map = {
  0:'0',
  1:'1',
  2:'2',
  3:'3',
  4:'4',
  5:'5',
  6:'6',
  7:'7',
  8:'8',
  9:'9',
  10:'K',
  11:'M',
  12:'B',
  13:'.',
  14:' ',
}

/* Digit column */
const column = (pos) => `<section data-digit = '${map[pos]}' class = 'f vs hs c animate offset-${pos}'>
  <div class = "digit">0</div>
  <div class = "digit">1</div>
  <div class = "digit">2</div>
  <div class = "digit">3</div>
  <div class = "digit">4</div>
  <div class = "digit">5</div>
  <div class = "digit">6</div>
  <div class = "digit">7</div>
  <div class = "digit">8</div>
  <div class = "digit">9</div>
  <div class = "digit">K</div>
  <div class = "digit">M</div>
  <div class = "digit">.</div>
</section>`;

/* Changes 1200 to 1.2K, etc. */
const preformat_number = N => {

 // Force string format
 N = String(N);

 // Empty values are 0
 if (N.length == 0)
   return '0';

 // Nothing to change
 if (N.length == 1 ||
     N.length == 2 ||
     N.length == 3)
     return N;

 // 1s of thousands
 if (N.length == 4)
   return `${N.charAt(0)}.${N.charAt(1)}K`;

 // 10s of thousands
 if (N.length == 5)
   return `${N.charAt(0)}${N.charAt(1)}.${N.charAt(2)}K`;

 // 100s of thousands
 if (N.length == 6)
   return `${N.charAt(0)}${N.charAt(1)}${N.charAt(2)}.${N.charAt(3)}K`;

 // 1s of millions
 if (N.length == 7)
   return `${N.charAt(0)}.${N.charAt(1)}M`;

 // 10s of millions
 if (N.length == 8)
   return `${N.charAt(0)}.${N.charAt(1)}M`;

 // 100s of thousands
 if (N.length == 9)
   return `${N.charAt(0)}${N.charAt(1)}${N.charAt(2)}.${N.charAt(3)}M`;

 // 1 billion
 if (N.length == 10)
   return `${N.charAt(0)}.${N.charAt(1)}B`;
};

class Numbers {

  constructor(string_container_id, number) {

  const target = $( string_container_id );

  if (!isNaN( number )) {

   this.string_container_id = string_container_id;

   // HTML container
   this.digits = ``;

   // Initialize number
   this.number = number;

   // Convert 1000 to 1K, 1200 to 1.2K, etc.
   this.string = preformat_number(this.number);

   // Break string into individual digits
   let split = this.string.split('');
   
   // Create HTML scaffold with 6 columns
   for (let i = 0; i < 6; i++) {
    if (6 - i > split.length)
     this.digits += `${column(14)}`;
    else {
     const index = i-(6-split.length);
     const digit = split[index];
     this.digits += `${column(mapping[digit])}`;
    }
   }

   // Insert into target container
   target.innerHTML = this.digits;
  }
 }

 clear = index => {
   for (let x = 0; x <= 14; x++)
    $$(`${this.string_container_id} section:nth-child(${index + 1}`).forEach(item => {
     /* reset the column style*/
     item.className = `f vs hs c animate`;
     /* empty it out */
     item.classList.add(`offset-14`);
    })
 }

 update = () => {

  /* Convert 1200 to "1.2K" in string format */
  this.string = preformat_number(this.number);

  /* Apply new class */
  let split = this.string.split('');
   for (let i = 0; i < 6; i++) {
    if (6 - i > split.length) {
     this.clear(i);
    } else {
     const index = i-(6-split.length);
     const digit = split[index];
     const child = `${this.string_container_id} section:nth-child(${i + 1})`;
     const offset = `f vs hs c animate offset-${mapping[digit]}`;

     /* animate */
     $(child).className = offset;
    }
   }
 }

 increase = by => {
  /* increase the value */
  this.number += by;
  /* update the animation */
  this.update();
 }
 
 decrease = by => {
   /* decrease the value */
   this.number -= by;
   /* avoid negative values */
   if (this.number < 0) this.number = 0;
   /* update the animation */
   this.update();
 }

} /* end of class Numbers */

 /* Your DOM just loaded */
  window.addEventListener('DOMContentLoaded', event => {
    
    /* Create numbers */
    let num1 = new Numbers(`#c1`, 0);
    let num2 = new Numbers(`#c2`, 0);
    let num3 = new Numbers(`#c3`, 0);

    /* Attach events to test buttons */
    $(`#bc1`).addEventListener("click", E => { num1.increase(1) });
    $(`#bc10`).addEventListener("click", E => { num1.increase(10) });
    $(`#bc100`).addEventListener("click", E => { num1.increase(100) });

    $(`#bl1`).addEventListener("click", E => { num2.increase(1) });
    $(`#bl10`).addEventListener("click", E => { num2.increase(10) });
    $(`#bl100`).addEventListener("click", E => { num2.increase(100) });

    $(`#br1`).addEventListener("click", E => { num3.increase(1) });
    $(`#br10`).addEventListener("click", E => { num3.increase(10) });
    $(`#br100`).addEventListener("click", E => { num3.increase(100) });

  });

  window.onload = event => {
    /* Your media (images, etc.) just loaded */
  }
              
            
!
999px

Console