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

              
                <div class="side-calendar">
  <div class="side-calendar__header">
    <a class="side-calendar__year-month">2024/07</a>
  </div>
  <table class="side-calendar__body">
    <thead>
      <tr>
        <th class="side-calendar__day">日</th>
        <th class="side-calendar__day">月</th>
        <th class="side-calendar__day">火</th>
        <th class="side-calendar__day">水</th>
        <th class="side-calendar__day">木</th>
        <th class="side-calendar__day">金</th>
        <th class="side-calendar__day">土</th>
      </tr>
    </thead>
    <tbody class="side-calendar__dates">
      <!-- 日付のセルを動的に生成 -->
    </tbody>
  </table>
</div>

              
            
!

CSS

              
                @use 'global' as *;
.side-calendar {
  width: 320px;
  background-color: ;
  text-align: center;
  border: 1px solid black;
}

.side-calendar__header {
  position: relative;
  background-color: white;
  padding-bottom: 16px;
  position: relative;
}

.side-calendar__body {
  margin-top: 10px;
  border-spacing: 5px;
  width: 100%;
}

.side-calendar__year-month {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
  color: #eb537b;
  font-family: Quicksand;
  font-size: 18px;
  font-weight: 500;
  line-height: 1;
  letter-spacing: 0.04em;
  text-align: center;
}

.side-calendar__day,
.side-calendar__date {
  padding: 0;
  font-family: Quicksand;
  font-size: 12px;
  line-height: 12px;
  letter-spacing: 0.04em;
  text-align: center;
  text-underline-position: from-font;
  text-decoration-skip-ink: none;
}
.side-calendar__day {
  color: $primary-90;
  font-weight: 700;
  width: 34px;
  height: 32px;
}


.side-calendar__date {
  font-weight: 500;
  width: 34px;
  height: 34px;
}

.side-calendar__date {
  border-radius: 50%;
}

              
            
!

JS

              
                document.addEventListener('DOMContentLoaded', () => {
  // カレンダーの日付を表示する要素を取得
  const calendarBody = document.querySelector('.side-calendar__dates');
  const today = new Date(); // 現在の日付を取得


  const generateCalendar = (year, month) => {
    // カレンダーの中身を初期化(前の月のデータをクリア)
    calendarBody.innerHTML = '';

    // 指定した年月の1日が何曜日かを取得(0:日曜, 1:月曜, ..., 6:土曜)
    const firstDay = new Date(year, month, 1).getDay();

    // 指定した年月の日数を取得
    const daysInMonth = new Date(year, month + 1, 0).getDate();

    let date = 1; // カレンダーに表示する日付
    const rowsNeeded = Math.ceil((daysInMonth + firstDay) / 7); // 必要な行数を計算

    // 行(週単位)を作成
    for (let i = 0; i < rowsNeeded; i++) {
      const row = document.createElement('tr'); // 新しい行を作成

      // 列(曜日ごとのセル)を作成
      for (let j = 0; j < 7; j++) {
        const cell = document.createElement('td'); // 新しいセルを作成

        if (i === 0 && j < firstDay) {
          // 1週目で月の初日より前の曜日は空白にする
          cell.textContent = '';
        } else if (date <= daysInMonth) {
          // その月の日付を埋める
          cell.textContent = date;
          date++; // 次の日付へ
        } else {
          // その月の日付が終了したら空白のセルを埋める
          cell.textContent = '';
        }

        row.appendChild(cell); // 行にセルを追加
      }
      calendarBody.appendChild(row); // カレンダーに行を追加
    }
  };

  // 固定された年月でカレンダーを生成(2024年7月)
  const year = 2024;
  const month = 6; // 0から始まるため6は7月
  generateCalendar(year, month);
});

              
            
!
999px

Console