<table class="chart mobile-optimised">
  <caption>
    Total Monthly Widget Sales
    <small>(1/1 - 12/31/2020)</small>
  </caption>

  <!-- Used to establish equal column-widths. -->
  <thead>
    <tr>
      <th></th>
      <td colspan="12"></td>
    </tr>
  </thead>

  <tbody>
    <!-- inline styles used so values can be entered more easily from the backend (php etc). e.g. width and height match the percentage data value. -->
    <!-- Note the use of the data-th attributes which are used to display headings for the mobile version. Therefore the Normal heading text must be duplicated in the data-th values as shown below. -->
    <tr>
      <th class="y-axis">
        <div class="rotate">Revenue <small>(US Dollars)</small></div>
        <ol class="segments">
          <li><b>$100k</b></li>
          <li><b>$80k</b></li>
          <li><b>$60k</b></li>
          <li><b>$40k</b></li>
          <li><b>$20k</b></li>
          <li class="zero"><b>$0k</b></li>
        </ol>
      </th>

      <!-- Classes below serve as styling "hooks"... -->
      <td style="width:70%" data-th="January" class="jan"><span style="height:70%"><b>$70k</b></span></td>
      <td style="width:10%" data-th="February" class="feb"><span style="height:10%"><b>$10k</b></span></td>
      <td style="width:20%" data-th="March" class="mar"><span style="height:20%"><b>$20k</b></span></td>
      <td style="width:40%" data-th="April" class="apr"><span style="height:40%"><b>$40k</b></span></td>
      <td style="width:100%" data-th="May" class="may"><span style="height:100%"><b>$100k</b></span></td>
      <td style="width:15%" data-th="June" class="jun"><span style="height:15%"><b>$15k</b></span></td>
      <td style="width:60%" data-th="July" class="jul"><span style="height:60%"><b>$60k</b></span></td>
      <td style="width:55%" data-th="August" class="aug"><span style="height:55%"><b>$55k</b></span></td>
      <td style="width:35%" data-th="September" class="sep"><span style="height:35%"><b>$35k</b></span></td>
      <td style="width:90%" data-th="October" class="oct"><span style="height:90%"><b>$90k</b></span></td>
      <td style="width:20%" data-th="November" class="nov"><span style="height:20%"><b>$20k</b></span></td>
      <td style="width:50%" data-th="December" class="dec"><span style="height:50%"><b>$50k</b></span></td>
    </tr>
  </tbody>

  <tfoot>
    <tr>
      <th class="empty"></th>
      <th scope="col">Jan</th>
      <th scope="col">Feb</th>
      <th scope="col">Mar</th>
      <th scope="col">Apr</th>
      <th scope="col">May</th>
      <th scope="col">Jun</th>
      <th scope="col">Jul</th>
      <th scope="col">Aug</th>
      <th scope="col">Sep</th>
      <th scope="col">Oct</th>
      <th scope="col">Nov</th>
      <th scope="col">Dec</th>
    </tr>
    <tr>
      <td class="emptyfoot"></td>
      <td class="x-axis" colspan="12">Month</td>
    </tr>
  </tfoot>
</table>
* {
  margin: 0;
  padding: 0;
}

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

body {
  font-family: Helvetica, Arial, Sans-Serif;
  font-weight: normal;
  line-height: 1.4em;
  font-size: 0.9em;
  color: #000;
}

.chart .jan span {
  background: green;
}

.chart .feb span {
  background: orange;
}

.chart .mar span {
  background: teal;
}

.chart .apr span {
  background: cyan;
}

.chart .may span {
  background: lightblue;
}

.chart .jun span {
  background: red;
}

.chart .jul span {
  background: magenta;
}

.chart .aug span {
  background: yellow;
}

.chart .sep span {
  background: skyblue;
}

.chart .oct span {
  background: gray;
}

.chart .nov span {
  background: aquamarine;
}

.chart .dec span {
  background: white;
}

/**************************************************************************/
/* DESKTOP (Horizontal)                                                   */
/**************************************************************************/
/* TABLE */
.chart {
  table-layout: fixed;
  width: 90%;
  max-width: 1240px;
  height: 60vh;
  /*border-collapse: collapse;*/
  border-spacing: 0; /* firefox bug with border mis-alignment*/
  margin: auto;
}

/* CAPTION */
caption {
  padding: 20px 0 10px 0;
  font-size: 1rem;
  font-weight: bold;
  text-align: center;
  line-height: 1.4;
}

caption > small {
  display: block;
  font-size: 0.8rem;
  font-weight: normal;
}

/* THEAD */
.chart thead th {
  border-right: 2px solid #000;
}

.chart thead td {
  height: 20px;
  background: #f9f9f9;
}

/* TFOOT */
.chart tfoot th {
  padding: 5px 0 0 0;
  vertical-align: top;
  font-size: 0.9rem;
  font-weight: normal;
  background-color: #fff;
}

.chart tfoot td.x-axis {
  padding: 0.4rem 0 0 0;
  font-size: 0.9rem;
  font-weight: bold;
  text-align: center;
}

/* TBODY */
.chart tbody {
  background: #f9f9f9;
  background-image: linear-gradient(rgba(0, 0, 0, 0.1) 1px, transparent 1px);
  background-size: 98% 10%;
}

/* TD */
.chart tbody td {
  vertical-align: bottom;
  height: 100%;
  padding: 0 10px;
  border-bottom: 2px solid #000;
}

/* BARS */
.chart tbody td span {
  position: relative;
  display: block;
  background: #99ffff;
  border-top: 1px solid #000;
  border-right: 1px solid #000;
  border-bottom: none;
  border-left: 1px solid #000;
  box-shadow: 5px 0px 5px rgba(0, 0, 0, 0.3);
}

/* BAR-VALUES */
.chart tbody td span b {
  position: absolute;
  display: block;
  bottom: 100%;
  left: 0;
  right: 0;
  text-align: center;
  font-weight: normal;
}

/* Y-AXIS LABEL + MARKERS */
.chart tbody th.y-axis {
  position: relative;
  border-right: 2px solid #000;
  background: #fff;
}

/* Transform Y-axis Label */
.rotate {
  position: relative;
  -ms-writing-mode: tb-lr;
  z-index: 3;
  margin: 1rem 1rem 0 0;
  font-size: 1rem;
  font-weight: bold;
}

@supports (writing-mode: vertical-lr) {
  .rotate {
    display: inline-block;
    writing-mode: vertical-lr;
    white-space: nowrap;
    transform: rotate(180deg) translateX(20px);
    line-height: 0;
  }
}

.rotate > small {
  font-size: 0.8rem;
  font-weight: normal;
}

/* Y-axis Markers */
ol.segments {
  position: absolute;
  top: 0;
  /* LOOK */
  bottom: 0;
  right: 3px;
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: 0.9rem;
  font-weight: normal;
  display: flex;
  flex-direction: column;
}

ol.segments li {
  flex: 1 0 0;
}
ol.segments li b {
  display: block;
  transform: translateY(-50%);
}
ol.segments li.zero {
  position: absolute;
  bottom: 0;
  right: 5px;
}
ol.segments li.zero b {
  transform: translateY(50%);
}

/**************************************************************************/
/* MOBILE (Vertical)                                                      */
/**************************************************************************/
@media screen and (max-width: 601px) {
  /* TABLE */
  .mobile-optimised {
    display: block;
    height: auto;
    width: 100%;
    overflow-wrap: break-word;
    border-spacing: 0;
  }

  /* CAPTION */
  .mobile-optimised caption {
    display: block;
    padding: 1rem 0;
  }

  /* THEAD + TFOOT */
  .mobile-optimised thead,
  .mobile-optimised tfoot {
    display: none;
  }

  /* TBODY */
  .mobile-optimised tbody,
  .mobile-optimised tr {
    display: block;
  }

  .mobile-optimised tbody:after,
  .mobile-optimised tr:after {
    content: "";
    display: block;
    clear: both;
    height: 0;
  }

  .mobile-optimised tbody {
    margin: 0 4rem 2rem 2rem;
    border-left: none;
    background: #f9f9f9;
  }

  /* TR */
  .mobile-optimised tbody tr {
    background-image: linear-gradient(to right, #ddd 1px, transparent 1px);
    background-size: 10% 100%;
    border-right: 1px solid #ddd;
  }

  /* TD */
  .mobile-optimised tbody td:before {
    content: attr(data-th);
    display: block;
    font-weight: bold;
    margin: 0 0 0 5px;
  }

  .mobile-optimised tbody td {
    display: block;
    float: left;
    height: auto;
    width: 100%;
    clear: both;
    margin: 0;
    padding: 1rem 0 0 0;
    white-space: nowrap;
    border-bottom: none;
    border-left: 2px solid #000;
    background: transparent;
  }

  .mobile-optimised tbody td:nth-child(2) {
    padding: 1.5rem 0 0 0;
  }

  .mobile-optimised tbody td:last-child {
    padding: 1rem 0 1.5rem 0;
  }

  /* BARS */
  .mobile-optimised tbody td span {
    position: relative;
    height: 25px !important;
    line-height: 25px;
    border-top: 1px solid #000;
    border-right: 1px solid #000;
    border-bottom: 1px solid #000;
    border-left: none;
    box-shadow: 0px 1px 1px rgba(0, 0, 0, 0.3);
  }

  /* BAR-VALUES */
  .mobile-optimised tbody td span b {
    position: absolute;
    left: 100%;
    top: 0;
    right: auto;
    bottom: 0;
    padding: 0 0 0 5px;
  }

  /* Y-AXIS LABEL + MARKERS */
  .mobile-optimised tbody th.y-axis {
    display: block;
    width: calc(100% + 2px);
    /* hide right border */
    padding-bottom: 1.4rem;
    border-right: none;
    border-bottom: 2px solid #000;
    border-left: none;
    background-color: #fff;
  }

  /* Y-axis Label */
  .mobile-optimised tbody .rotate {
    display: block;
    -ms-writing-mode: initial;
    writing-mode: initial;
    white-space: nowrap;
    transform: none;
    margin: 0;
    line-height: normal;
    font-size: 0.9rem;
  }

  /* Y-axis Markers */
  .mobile-optimised tbody ol.segments {
    position: absolute;
    top: auto;
    bottom: 0;
    right: 0;
    left: 0;
    /* LOOK */
    font-size: 0.9rem;
    flex-direction: row-reverse;
  }

  .mobile-optimised tbody ol.segments li {
    flex: 1 0 0;
    text-align: right;
  }
  ol.segments li b {
    display: inline-flex;
    transform: translate(50%, 0%);
  }
  ol.segments li.zero {
    left: 0;
    right: auto;
    bottom: auto;
    top: 0;
  }
  ol.segments li.zero b {
    transform: translate(-50%, 0%);
  }
}

/* End of MOBILE Styles. */
/* ANIMATION */
.chart span {
  opacity: 1;
  animation: barchart 2s ease reverse;
}

@keyframes barchart {
  to {
    height: 0%;
    opacity: 0;
  }
}
Run Pen

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.