← Back toCSS Layout

Calendar

Written byPhuoc Nguyen
Category
Display
Created
24 Sep, 2022

HTML

index.html
<div class="calendar">
<!-- Week days -->
<div class="calendar__weekday">Mon</div>
<div class="calendar__weekday">Tue</div>
<div class="calendar__weekday">Wed</div>
<div class="calendar__weekday">Thu</div>
<div class="calendar__weekday">Fri</div>
<div class="calendar__weekday">Sat</div>
<div class="calendar__weekday">Sun</div>

<!-- Days of the previous month -->
<div class="calendar__day calendar__day--disabled">30</div>
<div class="calendar__day calendar__day--disabled">31</div>

<!-- Days of the current month -->
<div class="calendar__day">1</div>
<div class="calendar__day">2</div>

<!-- The current day -->
<div class="calendar__day calendar__day--current">...</div>

<!-- Days of the next month -->
<div class="calendar__day calendar__day--disabled">1</div>
<div class="calendar__day calendar__day--disabled">2</div>
</div>

CSS

styles.css
.calendar {
display: grid;
grid-template-columns: repeat(7, 1fr);
}

.calendar__weekday {
border-bottom: 1px solid #d1d5db;
padding: 0.125rem;
}

.calendar__day {
border-bottom: 1px solid #d1d5db;
border-right: 1px solid #d1d5db;
padding: 0.25rem;
text-align: center;
}

.calendar__day--current {
background-color: #3b82f6;
color: #fff;
}

.calendar__day:nth-child(7n + 1) {
border-left: 1px solid #d1d5db;
}

.calendar__day--disabled {
color: #d1d5db;
}

Questions? 🙋

Do you have any questions? Not just about this specific post, but about any topic in front-end development that you'd like to learn more about? If so, feel free to send me a message on Twitter or send me an email. You can find them at the bottom of this page.
I have a long list of upcoming posts, but your questions or ideas for the next one will be my top priority. Let's learn together! Sharing knowledge is the best way to grow 🥷.

Recent posts ⚡

Newsletter 🔔

If you're into front-end technologies and you want to see more of the content I'm creating, then you might want to consider subscribing to my newsletter.
By subscribing, you'll be the first to know about new articles, products, and exclusive promotions.
Don't worry, I won't spam you. And if you ever change your mind, you can unsubscribe at any time.
Phước Nguyễn