Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs 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 its URL and the proper URL extension.

+ 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

Auto Save

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

              
                .calendar
  .header-year
  .header-month
  -['M', 'T', 'W', 'T', 'F', 'S', 'S'].each do |day|
    .day-of-week
      #{day}
  -(1..42).each do
    .day
   
              
            
!

CSS

              
                html {
  font-size: 14.3vmin; // 1/7
}

.inverse {
  background-color: black;
  color: white;
}

.calendar {
  display: grid;
  font-family: 'Helvetica', 'Arial', sans-serif;
  font-weight: bold;
  grid-template-columns: repeat(7, auto);
  letter-spacing: -0.09em;
  line-height: 0.8;
  margin: 0 auto;
  width: 95vw;
}

.header-year,
.header-month {
  font-size: 0.3em;
  letter-spacing: -0.05em;
  margin-top: 0.3em;
  margin-bottom: 1rem;
}

.day-of-week,
.day {
  border-left: 1px solid black;
  .inverse & {
    border-left: 1px solid white;
  }
}

.header-year {
  grid-column: 5;
}

.header-month {
  grid-column: 6 / 8;
}

              
            
!

JS

              
                // Moment-ception to get a Moment object for the current month
// (we can use this in the future to wire up a month switcher)
var currentMonth = moment().month(moment().month());

/**
 * Inverts colours if it’s an even-numbered month
 */
function setColor () {
  if (currentMonth.format('M') % 2 === 0) {
    document.querySelector('body').classList += 'inverse';
  }
}

/**
 * Renders year and month to header
 */
function renderHeader () {

  // Get year and month strings
  var yearString = currentMonth.format('YYYY');
  var monthString = currentMonth.format('MMMM');
  
  // Get DOM nodes to populate
  var headerYear = document.querySelector('.header-year');
  var headerMonth = document.querySelector('.header-month');

  // Populate said DOM nodes with year and month strings
  headerYear.innerHTML = yearString;
  headerMonth.innerHTML = monthString;
}

/**
 * Finds the first of the month and renders the days accordingly
 */
function renderCalendar () {

  // Get the day of the week of the first so we know where to start
  // numbering our days (handily, `isoWeekday` starts from Monday)
  var firstOfMonthWeekday = currentMonth.date(1).isoWeekday();
  
  // We also need to know when to stop numbering our days
  var lastOfMonth = currentMonth.endOf('month').date();

  // NodeList of slots in our calendar
  var dateList = document.querySelectorAll('.day');

  // Lop any calendar slots before the first off our list (a NodeList
  // isn’t really an array, so we can’t use `slice` directly).
  // `firstOfMonthWeekday` is one-indexed, so we have to subtract one
  // to get the index of the first in the returned array.
  var dates = Array.prototype.slice.call(dateList, (firstOfMonthWeekday - 1));

  // Loop through date array
  for (var i = 1; i <= lastOfMonth; i++) {
    
    // Again with the subtraction to get the correct index
    dates[i - 1].innerHTML = i;
  }
}

setColor();
renderHeader();
renderCalendar();

              
            
!
999px

Console