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

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

              
                <div class="wrap">
    <header>
        <div id="year"></div>
        <nav>
            <ul>
                <li id="this-year" class="nav-btn">今年</li>
                <li id="this-month" class="nav-btn">今月</li>
                <li id="prev" class="nav-btn">←</li>
                <li id="next" class="nav-btn">→</li>
            </ul>
        </nav>
    </header>
    <main>
        <div id="one-year" class="one-year fade active">
            <div></div>
            <div></div>
            <div></div>
            <div></div>
            <div></div>
            <div></div>
            <div></div>
            <div></div>
            <div></div>
            <div></div>
            <div></div>
            <div></div>
        </div>
        <div id="one-month" class="one-month fade"></div>
    </main>
</div>
              
            
!

CSS

              
                @charset "utf-8";
body {
    font-family: 游明朝, "Yu Mincho", YuMincho, "Hiragino Mincho ProN", "Hiragino Mincho Pro", HGS明朝E, メイリオ, Meiryo, serif;
    background-color: #f7feff;
}

.wrap {
    padding: 1vh 3vw;
}

header {
    overflow: hidden;
}

header #year {
    float: left;
    font-weight: bold;
    font-size: 1.4rem;
}

header nav {
    float: right;
}

.nav-btn {
    display: inline-block;
    border: #000 solid 1px;
    padding: 0 .3rem;
    cursor: pointer;
    background-color: #fff;
    font-size: 1rem;
    margin-left: .2rem;
    font-family: "游ゴシック Medium", YuGothic, YuGothicM, "Hiragino Kaku Gothic ProN", "Hiragino Kaku Gothic Pro", メイリオ, Meiryo, sans-serif;
}

main {
    position: relative;
}

.one-year {
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
}

.one-year table {
    cursor: pointer;
}

.one-month {
    width: 100%;
    position: absolute;
    top: 0;
    left: 0;
}

.one-month table {
    width: 100%;
    height: 70vh;
}

table {
    width: 29vw;
    margin-bottom: .4vh;
    background-color: #fff;
}

table,
td {
    border-collapse: collapse;
    border: 1px solid #333;
}

td,
th {
    text-align: center;
    font-size: .6rem;
}

.one-month th {
    padding: .4rem 0;
    font-size: 1rem;
}

.one-month td {
    font-size: 1.4rem;
}

caption {
    /* text-align: left; */
    font-weight: bold;
    font-size: .9rem;
}

.one-month caption {
    font-size: 1.6rem;
}

.fade {
    z-index: -1;
    opacity: 0;
    transform: scale(.95, .95);
    transition: .4s;
}

.fade.active {
    z-index: 1;
    opacity: 1;
    transform: scale(1, 1);
}

@media screen and (orientation: landscape) {
    .wrap {
        padding: 1.2rem;
    }
    header #year {
        font-size: 2rem
    }
    .nav-btn {
        padding: .4rem 1rem;
        cursor: pointer;
        font-size: 1rem;
        margin-left: 1rem;
    }
    .one-year table {
        width: 22vw;
        margin-bottom: 1rem;
    }
    td,
    th {
        font-size: .8rem;
    }
    caption {
        font-size: 1.2rem;
    }
}
              
            
!

JS

              
                'use strict';

const thisYear = document.getElementById('this-year');
const thisMonth = document.getElementById('this-month');
const today = document.getElementById('today');
const prev = document.getElementById('prev');
const next = document.getElementById('next');
const year = document.getElementById('year');
const month = document.getElementById('month');
const days = document.getElementById('days');
const oneYear = document.getElementById('one-year');
const oneMonth = document.getElementById('one-month');
const months = document.getElementById('one-year').querySelectorAll('div');
const now = new Date();
let displayDate = new Date();
let displayMode = 'year';

thisYear.addEventListener('click', function() {
    oneMonth.classList.remove('active');
    oneYear.classList.add('active');
    displayMode = 'year';
    displayDate = new Date();
    displayCalendar(displayDate.getFullYear());
});
thisMonth.addEventListener('click', function() {
    oneYear.classList.remove('active');
    oneMonth.classList.add('active');
    displayMode = 'month';
    displayDate = new Date();
    displayDate.setDate(1);
    year.innerHTML = displayDate.getFullYear() + '年';
    oneMonth.innerHTML = displayMonth(displayDate);
});
prev.addEventListener('click', function() {
    if (displayMode === 'year') {
        displayDate.setFullYear(displayDate.getFullYear() - 1);
        displayCalendar(displayDate.getFullYear());
    } else if (displayMode === 'month') {
        displayDate.setMonth(displayDate.getMonth() - 2);
        year.innerHTML = displayDate.getFullYear() + '年';
        oneMonth.innerHTML = displayMonth(displayDate);
    }
});
next.addEventListener('click', function() {
    if (displayMode === 'year') {
        displayDate.setFullYear(displayDate.getFullYear() + 1);
        displayCalendar(displayDate.getFullYear());
    } else if (displayMode === 'month') {
        year.innerHTML = displayDate.getFullYear() + '年';
        oneMonth.innerHTML = displayMonth(displayDate);
    }
});

months.forEach(function(el, i) {
    el.addEventListener('click', function() {
        if (displayMode === 'year') {
            oneYear.classList.remove('active');
            oneMonth.classList.add('active');
            displayMode = 'month';
            displayDate.setMonth(i);
            displayDate.setDate(1);
            oneMonth.innerHTML = displayMonth(displayDate);
        }
    });
});

displayCalendar(displayDate.getFullYear()); //最初にカレンダーを表示する

function displayCalendar(setCalendarYear) {
    const calendar = [];
    for (let i = 0; i < 12; i++) {
        calendar[i] = new Date(setCalendarYear, 0);
        year.innerHTML = calendar[i].getFullYear() + '年';
        calendar[i].setDate(1);
        calendar[i].setMonth(i);
        months[i].innerHTML = displayMonth(calendar[i]);
    }
}

function displayMonth(calendar) {
    let calendarTable = '';
    const calendarMonth = calendar.getMonth();
    const calendarDay = calendar.getDay();
    calendarTable += '<table><caption>' + (calendar.getMonth() + 1) + '月</caption>';
    calendarTable += '<colgroup id="sun" style="background-color:orange;"></colgroup><colgroup id="mon"></colgroup><colgroup id="tus"></colgroup><colgroup id="wen"></colgroup><colgroup id="thu"></colgroup><colgroup id="fri"></colgroup><colgroup id="sat" style="background-color:aqua;"></colgroup>'
    if (displayMode === 'month') {
        calendarTable += '<thead><tr><th style="color:red;">日</th><th>月</th><th>火</th><th>水</th><th>木</th><th>金</th><th style="color:blue;">土</th></tr></thead>';
    }
    calendarTable += '<tbody>';
    for (let i = 0; i < 42; i++) {
        if (i % 7 === 0) {
            calendarTable += '<tr>';
        }
        if (i >= calendarDay && calendarMonth === calendar.getMonth()) {
            if (now.getFullYear() === calendar.getFullYear() && now.getMonth() === calendar.getMonth() && now.getDate() === calendar.getDate()) {
                // 今日を表示
                calendarTable += '<td style="font-weight:bold;color:red;background-color:yellow;">' + calendar.getDate() + '</td>';
            } else {
                calendarTable += '<td>' + calendar.getDate() + '</td>';
            }
            calendar.setTime(calendar.getTime() + 86400000);
        } else {
            calendarTable += '<td> </td>';
        }
        if (i % 7 === 6) {
            calendarTable += '</tr>';
        }
    }
    calendarTable += '</tbody></table>';
    console.log(calendarTable);
    return calendarTable;
}
              
            
!
999px

Console