← Back toCSS layout

Calendar

Written byPhuoc Nguyen
Created
24 Sep, 2022
Category
Display

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;
}
If you found this post helpful, please consider giving the repository a star on GitHub or sharing the post on your favorite social networks 😍. Your support would mean a lot to me!

Questions? 🙋

Do you have any questions about front-end development? If so, feel free to create a new issue on GitHub using the button below. I'm happy to help with any topic you'd like to learn more about, even beyond what's covered in this post.
While I have a long list of upcoming topics, I'm always eager to prioritize your questions and ideas for future content. Let's learn and grow together! Sharing knowledge is the best way to elevate ourselves 🥷.
Ask me questions

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