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.

            
              <!-- Expanding on https://css-tricks.com/making-a-bar-chart-with-css-grid/ -->

<!-- Set "--scale" based on the data: in this case 100% -->
<!-- Set "--start" values calculated as: "<scale> + 1 - <value>" -->
<!-- (the +1 corrects for 1-index of grid-lines) -->

<dl class="chart">
  
  <dt class="date">2000</dt>
  <dd class="bar" style="--start: 56;">
    <span class="value">45%</span>
  </dd>

  <dt class="date">2001</dt> 
  <dd class="bar" style="--start: 1;">
    <span class="value">100%</span> 
  </dd>

  <dt class="date">2002</dt> 
  <dd class="bar" style="--start: 38;">
    <span class="value">63%</span> 
  </dd>

  <dt class="date">2003</dt> 
  <dd class="bar" style="--start: 90;">
    <span class="value">11%</span> 
  </dd>

  <dt class="date">2004</dt> 
  <dd class="bar" style="--start: 55;">
    <span class="value">46%</span> 
  </dd>

  <dt class="date">2005</dt> 
  <dd class="bar" style="--start: 13;">
    <span class="value">88%</span> 
  </dd>

  <dt class="date">2006</dt> 
  <dd class="bar" style="--start: 66;">
    <span class="value">35%</span> 
  </dd>

  <dt class="date">2007</dt> 
  <dd class="bar" style="--start: 96;">
    <span class="value">5%</span> 
  </dd>

  <dt class="date">2008</dt> 
  <dd class="bar" style="--start: 23;">
    <span class="value">78%</span> 
  </dd>

  <dt class="date">2009</dt> 
  <dd class="bar" style="--start: 10;">
    <span class="value">91%</span> 
  </dd>

  <dt class="date">2010</dt> 
  <dd class="bar" style="--start: 46;">
    <span class="value">55%</span> 
  </dd>

  <dt class="date">2011</dt> 
  <dd class="bar" style="--start: 85;">
    <span class="value">16%</span> 
  </dd>
  
</dl>
            
          
!
            
              .chart {
  --scale: 100;

  /* Setup the grid */
  display: grid;
  grid-auto-columns: 1fr;
  grid-template-rows: repeat(var(--scale), minmax(0, 1fr)) 1.4rem;
  grid-column-gap: 5px;

  /* Generate background guides */
  /* (sub-pixel rounding errors make this imperfect) */
  --line-every: 10;
  background-image: linear-gradient(to bottom, #ccc 1px, transparent 1px);
  background-size: 100% calc((100% - 1.4rem) / var(--scale) * var(--line-every));
  
  /* other styles… */
  margin: 2em auto 1em;
  padding: 0 1em;
  position: relative;
  max-width: 70vw;
  height: calc(100vh - 3em);
}

.chart::after {
  background: #fff;
  bottom: 0;
  content: ' ';
  height: 1.4rem;
  left: 0;
  position: absolute;
  right: 0;
}


/* Dates… */
/* ------ */

.date {
  align-items: center;
  display: flex;
  font-weight: bold;
  grid-row-start: -2;
  justify-content: center;
  text-align: center;
  z-index: 2;
}


/* Each bar on the graph… */
/* ---------------------- */

.bar {
  grid-row: var(--start) / -2;
  
  /* Background-Color */
  background-image: linear-gradient(to right, green, yellow, orange, red);
  background-size: 1600% 100%;
  background-position: calc(var(--start) * 1%) 0;
  
  /* Other styles… */
  border-radius: 5px 5px 0 0;
  color: #000;
  list-style: none;
  position: relative;
}

.value {
  background: #fff;
  bottom: 100%;  
  display: inline-block;
  left: 50%;
  padding: 0 0.4em;
  position: absolute;
  transform: translate(-50%, -1px);
}


/* Global helpers… */
/* --------------- */

:root {
  font-size: 80%;
  font-family: sans-serif;
}

* {
  box-sizing: border-box;
}

            
          
!
999px
Loading ..................

Console