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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ 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

              
                <h1>ICC World Cup, 2019</h1>
<h3>Vote for your Team</h3>

<div id="pollContainer">
    <div id="pollButtons">
        <ul>
           <li>Australia</li>
           <li>Bangladesh</li>
           <li>England</li>
           <li>India</li>
           <li>New Zealand</li>
           <li>Pakistan</li>
           <li>South Africa</li>
           <li>Sri Lanka</li>
           <li>West Indies</li>
           <li>Zimbabwe</li>
        </ul>
    </div>
</div>


              
            
!

CSS

              
                $baseColor: #f25757;
$auxColor: #fff;
$btnColor: #10659e;

body {
  background: rgba(52, 152, 219, 0.25);
  font: 18px 'Ubuntu', Helvetica, Arial, sans-serif;
  text-align: center;
  color: $baseColor;
  * {
    box-sizing: border-box;
    user-select: none;
  }
}

#pollContainer {
  max-width: 400px;
  margin: 3em auto;
  padding: 1.5em 5px;
  border-radius: 3px;
  box-shadow: 0 10px 20px -5px rgba(0, 0, 0, 0.3);
  position: relative;
  background: lighten($baseColor, 8%);
}

#pollButtons ul {
  display: flex;
  flex-wrap: wrap;
  list-style: none;
  margin: 0;
  padding: 0;
}

#pollButtons li {
  border: 1px solid $auxColor;
  margin: 5px auto;
  padding: 15px 0;
  color: $auxColor;
  width: 45%;
  border-radius: 5px;
  cursor: pointer;
  transition: all 0.4s ease;
  &:hover {
    // background: red;
    // color: #fff;
  }
}




              
            
!

JS

              
                // selectors
const poll = document.getElementById('pollButtons');
const pollBtns = poll.querySelectorAll('li');

// assigning initial values
let data = [];
for(let i=0; i<pollBtns.length; i++) {
    let r = Math.floor(Math.random() * 50);
    data.push(r);
}

[].forEach.call(pollBtns, (pollBtn) => {
    pollBtn.addEventListener('click', showResult);
});

function showResult() {
    let t = 0;
    for(let i=0; i<data.length; i++) {
        t += data[i];
    }
    let perc = data.map(j => Math.round(j*100/t));
    
    [].forEach.call(pollBtns, (pollBtn, i) => {
        let bg = `linear-gradient(90deg, #f25757 ${perc[i]}%, transparent ${perc[i]}%)`;
        pollBtn.style.backgroundImage = bg;
      
        pollBtn.removeEventListener('click', showResult);
    });
}



              
            
!
999px

Console