HTML preprocessors can make writing HTML more powerful or convenient. For instance, Markdown is designed to be easier to write and read for text documents and you could write a loop in Pug.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. So you don't have access to higher-up elements like the <html>
tag. If you want to add classes there that can affect the whole document, this is the place to do it.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. If you need things in the <head>
of the document, put that code here.
The resource you are linking to is using the 'http' protocol, which may not work when the browser is using https.
CSS preprocessors help make authoring CSS easier. All of them offer things like variables and mixins to provide convenient abstractions.
It's a common practice to apply CSS to a page that styles elements such that they are consistent across all browsers. We offer two of the most popular choices: normalize.css and a reset. Or, choose Neither and nothing will be applied.
To get the best cross-browser support, it is a common practice to apply vendor prefixes to CSS properties and values that require them to work. For instance -webkit-
or -moz-
.
We offer two popular choices: Autoprefixer (which processes your CSS server-side) and -prefix-free (which applies prefixes via a script, client-side).
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.
You can apply CSS to your Pen from any stylesheet on the web. Just put a URL to it here and we'll apply it, in the order you have them, before the CSS in the Pen itself.
You can also link to another Pen here (use the .css
URL Extension) and we'll pull the CSS from that Pen and include it. If it's using a matching preprocessor, use the appropriate URL Extension and we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
JavaScript preprocessors can help make authoring JavaScript easier and more convenient.
Babel includes JSX processing.
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.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
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.
Using packages here is powered by esm.sh, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ESM usage.
All packages are different, so refer to their docs for how they work.
If you're using React / ReactDOM, make sure to turn on Babel for the JSX processing.
If active, Pens will autosave every 30 seconds after being saved once.
If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.
If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.
Visit your global Editor Settings.
<div class="calendar_area">
<div class="calendar_header">
<p id="year_month_label"></p>
<button id="prev_year_btn" onClick="prev_year()"><i class="fas fa-angle-double-left"></i></button>
<button id="prev_month_btn" onClick="prev_month()"><i class="fas fa-angle-left"></i></button>
<button id="now_btn" onClick="now_month()"><i class="fas fa-circle"></i></button>
<button id="next_month_btn" onClick="next_month()"><i class="fas fa-angle-right"></i></button>
<button id="next_year_btn" onClick="next_year()"><i class="fas fa-angle-double-right"></i></button>
</div>
<div id="calendar_body"></div>
</div>
/* ヘッダー(年月とボタン) */
div.calendar_header {
text-align: center;
}
/* 年月 */
div.calendar_header > p#year_month_label {
margin: 20px 20px 10px;
font-size: 1.5em;
font-weight: bold;
}
/* ボタン */
button#prev_year_btn,
button#prev_month_btn,
button#now_btn,
button#next_month_btn,
button#next_year_btn {
width: 3em;
height: 2em;
}
/* カレンダーテーブル */
table.calendar_tbl {
min-width: 600px;
margin: 20px auto 0;
border: 1px solid;
border-collapse: collapse;
}
/* カレンダーテーブルの見出し(曜日) */
table.calendar_tbl tr th {
text-align: center;
border: 1px solid #000;
}
/* カレンダーテーブルの見出し(日曜日) */
table.calendar_tbl tr th:first-child {
color: #f00;
}
/* カレンダーテーブルの見出し(土曜日) */
table.calendar_tbl tr th:last-child {
color: #00f;
}
/* カレンダーテーブルの日付部分 */
table.calendar_tbl tr td {
vertical-align: middle;
text-align: center;
border: 1px solid #000;
height: 3em;
}
/* カレンダーテーブルで日付が入らない部分 */
table.calendar_tbl tr td.no_date {
background-color: #f2f2f2;
}
/* カレンダーテーブルの日付の部分(日曜日) */
table.calendar_tbl tr td:first-child {
z-index: 10;
background-color: #fadbda;
color: #f00;
}
/* カレンダーテーブルの日付の部分(土曜日) */
table.calendar_tbl tr td:last-child {
background-color: #ddeeff;
color: #00f;
}
/* マウスオーバー時 */
table.calendar_tbl tr td.with_date:hover {
background-color: #fadfc0;
}
// 曜日の定義
const week = ["日", "月", "火", "水", "木", "金", "土"];
// 今日の日付
var today = new Date();
// 表示用の日付
var showDate = new Date(today.getFullYear(), today.getMonth(), 1);
// 表示された時
window.onload = function () {
// カレンダーの表示(引数には表示用の日付を設定)
showCalendar(showDate);
};
/**
* カレンダーの表示
*/
function showCalendar(date) {
// 年
var year = date.getFullYear();
// 月
var month = date.getMonth() + 1;
// ヘッダーの年月に表示する文字列
var showDateStr = year + "年 " + month + "月";
// ヘッダーの年月部分に埋め込み
document.querySelector('#year_month_label').innerHTML = showDateStr;
// カレンダーテーブルを作成する(HTMLが返却される)
var calendarTable = createCalendarTable(year, month);
// カレンダー表示部分に埋め込み
document.querySelector('#calendar_body').innerHTML = calendarTable;
}
/**
* カレンダーテーブルの作成
*/
function createCalendarTable(year, month) {
// HTML用の変数
var _html = '';
// tableタグ
_html += '<table class="calendar_tbl">';
// テーブルのヘッダー(曜日)
_html += '<tr>';
for (var i = 0; i < week.length; i++) {
_html += "<th>" + week[i] + "</th>";
}
_html += '</tr>';
// ---------------------
// 表示するカレンダー年月の1日の曜日を取得
var startDayOfWeek = new Date(year, month - 1, 1).getDay();
// 日付
var countDay = 0;
// 月の末日
var monthOfEndDay = new Date(year, month, 0).getDate()
// 6行分繰り返し
for (var i = 0; i < 6; i++) {
_html += '<tr>';
// 7列(曜日の数)分繰り返し
for (var j = 0; j < week.length; j++) {
// 1行目で開始曜日と同じ場合
if (i == 0 && j == startDayOfWeek) {
// 日付+1
countDay++;
// tdタグ(日付有りが分かるようにクラス属性に"with_date"を設定)
_html += '<td class="with_date">' + countDay + '</td>';
}
// 日付が0以外で、日付が末日より小さい場合
else if (countDay != 0 && countDay < monthOfEndDay) {
// 日付+1
countDay++;
// tdタグ(日付有りが分かるようにクラス属性に"with_date"を設定)
_html += '<td class="with_date">' + countDay + '</td>';
}
else {
// tdタグ(日付無しが分かるようにクラス属性に"no_date"を設定)
_html += '<td class="no_date"></td>';
}
}
_html += '</tr>';
}
_html += '</table>';
// 組み立てたHTMLを返却
return _html;
}
/**
* 前年
*/
function prev_year() {
// 表示用の日付の年-1を設定
showDate.setFullYear(showDate.getFullYear() - 1);
// カレンダーの表示(引数には表示用の日付を設定)
showCalendar(showDate);
}
/**
* 前月
*/
function prev_month() {
// 表示用の日付の月-1を設定
showDate.setMonth(showDate.getMonth() - 1);
// カレンダーの表示(引数には表示用の日付を設定)
showCalendar(showDate);
}
/**
* 今日
*/
function now_month() {
// 表示用の日付に今日の日付を設定
showDate = new Date();
// カレンダーの表示(引数には表示用の日付を設定)
showCalendar(showDate);
}
/**
* 来月
*/
function next_month() {
// 表示用の日付の月+1を設定
showDate.setMonth(showDate.getMonth() + 1);
// カレンダーの表示(引数には表示用の日付を設定)
showCalendar(showDate);
}
/**
* 来年
*/
function next_year() {
// 表示用の日付の年+1を設定
showDate.setFullYear(showDate.getFullYear() + 1);
// カレンダーの表示(引数には表示用の日付を設定)
showCalendar(showDate);
}
Also see: Tab Triggers