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

              
                <!-- days sourced from: https://nationaldaycalendar.com/february/ -->

<div class="container">

	<div class="header">

		<div class="title">
			<h1>FEBRUARY 2022</h1>
			<p>Holidays and Daily Observances in the United States</p>
		</div>

	</div>

	<div class="calendar-container">

		<div class="rowHeader">

			<div>SUNDAY</div>
			<div>MONDAY</div>
			<div>TUESDAY</div>
			<div>WEDNESDAY</div>
			<div>THURSDAY</div>
			<div>FRIDAY</div>
			<div>SATURDAY</div>

		</div>

		<!-- START OF ROW 1 -->

		<div class="row1">

			<div class="cell col1">
				<p class="number"></p>
				<img class="image">
				<a class="link" target="_blank">
					<p class="observance"></p>
				</a>
			</div>
			<div class="cell col2">
				<p class="number"></p>
				<img class="image">
				<a class="link" target="_blank">
					<p class="observance"></p>
				</a>
			</div>
			<div class="cell col3">
				<p class="number"></p>
				<img class="image">
				<a class="link" target="_blank">
					<p class="observance"></p>
				</a>
			</div>
			<div class="cell col4">
				<p class="number"></p>
				<img class="image">
				<a class="link" target="_blank">
					<p class="observance"></p>
				</a>
			</div>
			<div class="cell col5">
				<p class="number"></p>
				<img class="image">
				<a class="link" target="_blank">
					<p class="observance"></p>
				</a>
			</div>
			<div class="cell col6">
				<p class="number"></p>
				<img class="image">
				<a class="link" target="_blank">
					<p class="observance"></p>
				</a>
			</div>
			<div class="cell col7">
				<p class="number"></p>
				<img class="image">
				<a class="link" target="_blank">
					<p class="observance"></p>
				</a>
			</div>
		</div>

		<!-- END OF ROW 1 -->

		<!-- START OF ROW 2 -->

		<div class="row2">

			<div class="cell col1">
				<p class="number"></p>
				<img class="image">
				<a class="link" target="_blank">
					<p class="observance"></p>
				</a>
			</div>
			<div class="cell col2">
				<p class="number"></p>
				<img class="image">
				<a class="link" target="_blank">
					<p class="observance"></p>
				</a>
			</div>
			<div class="cell col3">
				<p class="number"></p>
				<img class="image">
				<a class="link" target="_blank">
					<p class="observance"></p>
				</a>
			</div>
			<div class="cell col4">
				<p class="number"></p>
				<img class="image">
				<a class="link" target="_blank">
					<p class="observance"></p>
				</a>
			</div>
			<div class="cell col5">
				<p class="number"></p>
				<img class="image">
				<a class="link" target="_blank">
					<p class="observance"></p>
				</a>
			</div>
			<div class="cell col6">
				<p class="number"></p>
				<img class="image">
				<a class="link" target="_blank">
					<p class="observance"></p>
				</a>
			</div>
			<div class="cell col7">
				<p class="number"></p>
				<img class="image">
				<a class="link" target="_blank">
					<p class="observance"></p>
				</a>
			</div>
		</div>

		<!-- END OF ROW 2-->

		<!-- START OF ROW 3 -->

		<div class="row3">

			<div class="cell col1">
				<p class="number"></p>
				<img class="image">
				<a class="link" target="_blank">
					<p class="observance"></p>
				</a>
			</div>
			<div class="cell col2">
				<p class="number"></p>
				<img class="image">
				<a class="link" target="_blank">
					<p class="observance"></p>
				</a>
			</div>
			<div class="cell col3">
				<p class="number"></p>
				<img class="image">
				<a class="link" target="_blank">
					<p class="observance"></p>
				</a>
			</div>
			<div class="cell col4">
				<p class="number"></p>
				<img class="image">
				<a class="link" target="_blank">
					<p class="observance"></p>
				</a>
			</div>
			<div class="cell col5">
				<p class="number"></p>
				<img class="image">
				<a class="link" target="_blank">
					<p class="observance"></p>
				</a>
			</div>
			<div class="cell col6">
				<p class="number"></p>
				<img class="image">
				<a class="link" target="_blank">
					<p class="observance"></p>
				</a>
			</div>
			<div class="cell col7">
				<p class="number"></p>
				<img class="image">
				<a class="link" target="_blank">
					<p class="observance"></p>
				</a>
			</div>
		</div>

		<!-- END OF ROW 3 -->

		<!-- START OF ROW 4 -->

		<div class="row4">

			<div class="cell col1">
				<p class="number"></p>
				<img class="image">
				<a class="link" target="_blank">
					<p class="observance"></p>
				</a>
			</div>
			<div class="cell col2">
				<p class="number"></p>
				<img class="image">
				<a class="link" target="_blank">
					<p class="observance"></p>
				</a>
			</div>
			<div class="cell col3">
				<p class="number"></p>
				<img class="image">
				<a class="link" target="_blank">
					<p class="observance"></p>
				</a>
			</div>
			<div class="cell col4">
				<p class="number"></p>
				<img class="image">
				<a class="link" target="_blank">
					<p class="observance"></p>
				</a>
			</div>
			<div class="cell col5">
				<p class="number"></p>
				<img class="image">
				<a class="link" target="_blank">
					<p class="observance"></p>
				</a>
			</div>
			<div class="cell col6">
				<p class="number"></p>
				<img class="image">
				<a class="link" target="_blank">
					<p class="observance"></p>
				</a>
			</div>
			<div class="cell col7">
				<p class="number"></p>
				<img class="image">
				<a class="link" target="_blank">
					<p class="observance"></p>
				</a>
			</div>
		</div>

		<!-- END OF ROW 4 -->

		<!-- START OF ROW 5 -->

		<div class="row5">

			<div class="cell col1">
				<p class="number"></p>
				<img class="image">
				<a class="link" target="_blank">
					<p class="observance"></p>
				</a>
			</div>
			<div class="cell col2">
				<p class="number"></p>
				<img class="image">
				<a class="link" target="_blank">
					<p class="observance"></p>
				</a>
			</div>
			<div class="cell col3">
				<p class="number"></p>
				<img class="image">
				<a class="link" target="_blank">
					<p class="observance"></p>
				</a>
			</div>
			<div class="cell col4">
				<p class="number"></p>
				<img class="image">
				<a class="link" target="_blank">
					<p class="observance"></p>
				</a>
			</div>
			<div class="cell col5">
				<p class="number"></p>
				<img class="image">
				<a class="link" target="_blank">
					<p class="observance"></p>
				</a>
			</div>
			<div class="cell col6">
				<p class="number"></p>
				<img class="image">
				<a class="link" target="_blank">
					<p class="observance"></p>
				</a>
			</div>
			<div class="cell col7">
				<p class="number"></p>
				<img class="image">
				<a class="link" target="_blank">
					<p class="observance"></p>
				</a>
			</div>
		</div>

		<!-- END OF ROW 5 -->

	</div>

</div>
              
            
!

CSS

              
                :root {
	--cellWidthSmall: 110px;
		
	--calendarWidthSmall: 785px;
	
	--description: 15%;
	
}

.container {
	display: flex;
	flex-direction: column;
}

.header {
	background-image: url("https://www.nationalobserver.com/sites/nationalobserver.com/files/img/2018/12/28/adventure-alpine-alps-714258.jpg");

	background-position: center;

	text-align: center;

	color: white;

	margin: 0 auto;

	border: 2px solid black;

	border-bottom: none;

	border-radius: 5px 5px 0 0;
}

.title {
	background-color: black;

	margin: 0 auto;
	border: 2px solid black;
}

.calendar-container {
	display: flex;
	flex-direction: column;

	background-color: white;

	margin: 0 auto;

	border: 2px solid black;

	border-radius: 0 0 5px 5px;
}

.rowHeader {
	display: flex;
	flex-direction: row;

	background-color: Wheat;

	text-align: center;

	font-weight: bold;

	align-items: center;

	border-bottom: 2px solid black;
}

.row1,
.row2,
.row3,
.row4,
.row5 {
	display: flex;
	flex-direction: row;
}

.cell {
	display: flex;
	flex-direction: column;

	border: 1px solid gray;
}

.cell .number {
	text-align: right;
}

.cell .image {
	display: block;

	width: 100px;
	height: 75px;

	margin-left: auto;

	margin-right: auto;
}

.cell .link {	
	text-align: center;
}

.col1 {
	border-left: none;
}

.col7 {
	border-right: none;
}

.row1 .cell {
	border-top: none;
}

.cell a,
.cell .observance {
	text-decoration: none;

	color: blue;
}

.cell a:visited,
.cell .observance:visited {
	color: blue;
}

/* START OF MEDIA QUERIES */

@media screen and (min-width: 320px) {
	h1 {
		font-size: 1em;
	}

	.title p {
		font-size: 1em;
	}

	.header {
		width: var(--calendarWidthSmall);
	}

	.title {
		width: 40%;
	}

	.calendar-container {		
		var(--calendarWidthSmall);
	}

	.row1,
	.row2,
	.row3,
	.row4,
	.row5 {		
		var(--calendarWidthSmall);
		
		height: 200px;
		
	}
	
	.rowHeader{
		
		width: var(--calendarWidthSmall);
		
	}
	
	.rowHeader div {
		
		width: var(--cellWidthSmall);
		
		font-size: 0.75em;
	}

	.cell {
		width: var(--cellWidthSmall);
	}

	.cell .number {
		margin: 5% 50%;

		font-weight: bold;

		font-size: 1em;
	}
}

@media screen and (min-width: 540px) {
	.cell {
		height: 190px;
	}
}

@media screen and (min-width: 1600px) {
	h1 {
		font-size: 2.5em;

		margin-top: 10%;
	}

	.title p {
		font-size: 1.5em;

		margin-top: 10%;
	}

	.header {
		width: 60vw;
		height: 30vh;
	}

	.title {
		width: 25%;
		height: 100%;
	}

	.calendar-container {
		width: 60vw;
		height: 130vh;

		overflow-y: hidden;

		overflow-x: hidden;
	}

	.rowHeader {
		width: 100%;
		height: 5vh;
		
		font-size: 1.5em;
	}

	.rowHeader div {
		width: 20%;
	}

	.row1,
	.row2,
	.row3,
	.row4,
	.row5 {
		width: 100%;
		height: 20%;
	}

	.cell {
		width: 20%;
		height: 100%;
	}

	.cell .number {
		margin: 5% 15%;

		font-weight: bold;

		font-size: 1.5em;
	}

	.cell .observance {
		font-size: 1.2em;

		/* margin: 10% 0 0 0; */
	}
}

              
            
!

JS

              
                window.addEventListener("DOMContentLoaded", (event) => {
	let observances = [
		"Dark Chocolate Day",
		"Groundhog Day",
		"Carrot Cake Day",
		"Wear Red Day",
		"Weatherperson's Day",
		"Chopsticks Day",
		"Periodic Table Day",
		"Kite Flying Day",
		"Pizza Day",
		"Umbrella Day",
		"Inventor's Day",
		"Global Movie Day",
		"Tortellini Day",
		"Valentine's Day",
		"Gumdrop Day",
		"Do a Grouch a Favor Day",
		"Cabbage Day",
		"Battery Day",
		"Chocolate Mint Day",
		"Love Your Pet Day",
		"President's Day",
		"Cook a Sweet Potato Day",
		"Tile Day",
		"Toast Day",
		"Clam Chowder Day",
		"Pistachio Day",
		"Polar Bear Day",
		"Tooth Fairy Day"
	];

	let images = [
		"https://adevelopersprofile.com/CodePen/Challenges/Calendar/dark_chocolate.jpg",
		"https://adevelopersprofile.com/CodePen/Challenges/Calendar/groundhog_day.jpg",
		"https://adevelopersprofile.com/CodePen/Challenges/Calendar/carrot_cake.jpg",
		"https://adevelopersprofile.com/CodePen/Challenges/Calendar/wear_red_day.jpg",
		"https://adevelopersprofile.com/CodePen/Challenges/Calendar/weather_day.jpg",
		"https://adevelopersprofile.com/CodePen/Challenges/Calendar/chopsticks.jpg",
		"https://adevelopersprofile.com/CodePen/Challenges/Calendar/periodic_table.png",
		"https://adevelopersprofile.com/CodePen/Challenges/Calendar/kite.jpg",
		"https://adevelopersprofile.com/CodePen/Challenges/Calendar/pizza.jpg",
		"https://adevelopersprofile.com/CodePen/Challenges/Calendar/umbrella.jpg",
		"https://adevelopersprofile.com/CodePen/Challenges/Calendar/inventors.jpg",
		"https://adevelopersprofile.com/CodePen/Challenges/Calendar/movie.jpg",
		"https://adevelopersprofile.com/CodePen/Challenges/Calendar/tortillini.jpg",
		"https://adevelopersprofile.com/CodePen/Challenges/Calendar/valentines_day.jpg",
		"https://adevelopersprofile.com/CodePen/Challenges/Calendar/gumdrop.jpg",
		"https://adevelopersprofile.com/CodePen/Challenges/Calendar/grouch.jpg",
		"https://adevelopersprofile.com/CodePen/Challenges/Calendar/cabbage.jpg",
		"https://adevelopersprofile.com/CodePen/Challenges/Calendar/battery.jpg",
		"https://adevelopersprofile.com/CodePen/Challenges/Calendar/mint.jpg",
		"https://adevelopersprofile.com/CodePen/Challenges/Calendar/pets.jpg",
		"https://adevelopersprofile.com/CodePen/Challenges/Calendar/presidents.jpg",
		"https://adevelopersprofile.com/CodePen/Challenges/Calendar/sweet_potato.jpg",
		"https://adevelopersprofile.com/CodePen/Challenges/Calendar/tile.jpg",
		"https://adevelopersprofile.com/CodePen/Challenges/Calendar/toast.jpg",
		"https://adevelopersprofile.com/CodePen/Challenges/Calendar/clam_chowder.jpg",
		"https://adevelopersprofile.com/CodePen/Challenges/Calendar/pistachio.jpg",
		"https://adevelopersprofile.com/CodePen/Challenges/Calendar/polar_bear.jpg",
		"https://adevelopersprofile.com/CodePen/Challenges/Calendar/tooth_fairy.png"
	];

	let alternates = [
		"Picture Of Dark Chocolate Chunks",
		"A Groundhog Picture",
		"A Carrot Cake Picture",
		"Wear Red Day Picture",
		"Picture Of A Weatherman",
		"Picture Of A Pair Of Chopsticks",
		"Periodic Table Picture",
		"Picture Of A Kite Flying",
		"Picture Of A Pizza",
		"An Umbrella Picture",
		"Picture Of An Inventor",
		"Picture Of A Movie Reel",
		"Picture Of Tortellini",
		"Picture Of A Valentine's Day Heart",
		"Picture Of Gumdrops",
		"Oscar The Grouch Picture",
		"Picture Of A Cabbage",
		"A Duracell Battery Picture",
		"Picture Of A Half Eaten Chocolate Mint",
		"Picture Of A Dog And Cat",
		"Picture Of Mount Rushmore",
		"Picture Of Sweet Potatoes",
		"A Tiled Quilt Picture",
		"A Picture Of Cooked Toast",
		"A Picture Of A Bowl Of Clam Chowder",
		"Picture Of Pistachioes",
		"Picture Of A Polar Bear",
		"Cartoon Picture Of The Tooth Fairy"
	];

	let links = [
		"https://nationaldaycalendar.com/national-dark-chocolate-day-february-1/",
		"https://nationaldaycalendar.com/national-groundhog-day-february-2/",
		"https://nationaldaycalendar.com/national-carrot-cake-day-february-3/",
		"https://nationaldaycalendar.com/world-cancer-day-february-4/",
		"https://nationaldaycalendar.com/national-weatherpersons-day-february-5/",
		"https://nationaldaycalendar.com/national-chopsticks-day-february-6/",
		"https://nationaldaycalendar.com/national-periodic-table-day-february-7/",
		"https://nationaldaycalendar.com/national-kite-flying-day-february-8/",
		"https://nationaldaycalendar.com/national-pizza-day-february-9/",
		"https://nationaldaycalendar.com/national-umbrella-day-february-10/",
		"https://nationaldaycalendar.com/national-inventors-day-february-11/",
		"https://nationaldaycalendar.com/global-movie-day-second-saturday-in-february/",
		"https://nationaldaycalendar.com/national-tortellini-day-february-13/",
		"https://nationaldaycalendar.com/valentines-day-february-14/",
		"https://nationaldaycalendar.com/national-gumdrop-day-february-15/",
		"https://nationaldaycalendar.com/national-do-a-grouch-a-favor-day-february-16/",
		"https://nationaldaycalendar.com/national-cabbage-day-february-17/",
		"https://nationaldaycalendar.com/national-battery-day-february-18/",
		"https://nationaldaycalendar.com/national-chocolate-mint-day-february-19/",
		"https://nationaldaycalendar.com/national-love-your-pet-day-february-20/",
		"https://www.history.com/topics/holidays/presidents-day",
		"https://nationaldaycalendar.com/national-cook-a-sweet-potato-day-february-22/",
		"https://nationaldaycalendar.com/national-tile-day-february-23/",
		"https://www.daysoftheyear.com/days/toast-day/#:~:text=National%20Toast%20Day%20(February%2024th,2022)%20%E2%80%93%20Days%20Of%20The%20Year",
		"https://nationaldaycalendar.com/national-clam-chowder-day-february-25/",
		"https://nationaldaycalendar.com/national-pistachio-day-february-26/",
		"https://nationaldaycalendar.com/national-polar-bear-day-february-27/",
		"https://nationaldaycalendar.com/national-tooth-fairy-day-february-28/"
	];

	/*** GET CURRENT DATE DETAILS ***/

	let date = new Date();

	let currentDay = date.getDay();
	let currentMonth = date.getMonth();
	let currentYear = date.getFullYear();

	function getNumberOfDays(month) {
		// 0 = Jan, 1 = Feb, 2 = March, 3 = April, 4 = May, 5 = June, 6 = July, 7 = August, 8 = Sep, 9 = Oct,
		// 10 = Nov, 11 = Dec;

		let days = 0;

		switch (month) {
			case 0:
			case 2:
			case 4:
			case 6:
			case 7:
			case 9:
			case 11:
				days = 31;

				break;

			case 3:
			case 5:
			case 8:
			case 10:
				days = 30;

				break;

			case 1:
				let leap = checkLeapYear();

				if (leap) {
					days = 29;
				} else {
					days = 28;
				}

				break;
		}

		return days;
	}

	function checkLeapYear() {
		return true
			? (currentYear % 100 === 0 || currentYear % 400 !== 0) &&
					currentYear % 4 == 0
			: false;
	}

	// Add data to the calendar cells

	let startDate = new Date("February 1, 2022");

	let startDay = startDate.getDay();

	let grid;

	let numDaysInMonth = getNumberOfDays(currentMonth);

	let daysToAdd = 0;

	let dayNumber = 0;

	let previousMonth = currentMonth - 1;

	let numDaysInPreviousMonth = getNumberOfDays(previousMonth);

	let remainder = startDay - 1;

	let startDayNextMonth = 1;

	for (let i = 0; i < 5; i++) {
		switch (i) {
			case 0:
				grid = document.querySelector(".row1");

				daysToAdd = 7;

				break;

			case 1:
				grid = document.querySelector(".row2");

				daysToAdd = 7;

				break;

			case 2:
				grid = document.querySelector(".row3");

				daysToAdd = 7;

				break;

			case 3:
				grid = document.querySelector(".row4");

				daysToAdd = 7;

				break;

			case 4:
				grid = document.querySelector(".row5");

				daysToAdd = numDaysInMonth - 21;

				break;
		}

		let cells = grid.querySelectorAll(".cell");

		for (let j = 0; j < daysToAdd; j++) {
			let number = cells[j].querySelector(".number");
			let observance = cells[j].querySelector(".observance");
			let image = cells[j].querySelector(".image");
			let link = cells[j].querySelector(".link");

			if (i == 0 && j == startDay) {
				dayNumber = 1;
			}

			if (dayNumber > 0 && dayNumber <= numDaysInMonth) {
				number.innerText = dayNumber;
				observance.innerText = observances[dayNumber - 1];
				image.src = images[dayNumber - 1];
				link.href = links[dayNumber - 1];
				link.alt = alternates[dayNumber - 1];

				dayNumber++;
			} else {
				cells[j].style.backgroundColor = "lightgray";
				number.innerText = numDaysInPreviousMonth - remainder;
				image.style.width = 0;
				remainder = remainder - 1;

				if (dayNumber == numDaysInMonth + 1) {
					number.innerText = startDayNextMonth;

					startDayNextMonth = startDayNextMonth + 1;
				}
			}
		}
	}
});

              
            
!
999px

Console