Alternative
Amazon
Article
Writing
Art
AI
Angular
Photoshop
Premiere
Animal Crossing
Blog
Story
Android
Android Studio
Davinci Resolve
CSS
Clipchamp
ChatGPT
Crypto
DALL-E
Discord
Davinci Resolve
Davinci Resolve 18
Dream Studio
Express
Filmora
Flutter
PC Games
Git
GPT
GPT3
GPT4
GTA
GTA 6
Ghost Together
Ghost Together
HTML
iOS
iMovie
Illustrator
JavaScript
Mac
Mongo
Midjourney
Minecraft
Node.js
NBA 2k24
OSX
PHP
Palworld
Python
Playground AI
Roblox
React
Recipe (Cooking)
React Native
Semicolon.dev
Starfield PC Game
Snapchat
Steam
Stable Diffusion
SVG
Threads
Text To Image (AI)
VSCode
Vim
Web Development
Windows
WebGL

CSS Flex Calendar

viewed 1.9K times
› tutorials › css › flex calendar
(Help spread the word about this article)

I needed to create a calendar for Semicolon's coding mentorship program. A student would pick a month and a day and select a mentor based on their available hours. (If they match mentor's availability lane or not already scheduled by other students.)

So here was my thinking behind making CSS Flex Calendar:

  1. For this project I have to use CSS Flex, not CSS Grid.
  2. Create representation of a calendar cell (two types for empty cells and day cells)
  3. Using flex-wrap:wrap will drop days to next row.
  4. (By default flex doesn't create a line break for long lines)
  5. HTML scaffold containing all days

Calendars with day pickers require a bit more CSS and JavaScript. But the first step is to create the layout. I know grid is probably a more natural solution but for my setup I had to make it with flex. So I'm not saying this is a complete flex calendar, only a basic layout.

Example of Flex calendar built with source code on this page (see below):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31

Empty spaces should be calculated programatically but at this point I simply inserted several div elements.

Flex is one of the quickest ways of making a simple calendar. Calendars are basically grids. And CSS grid is probably a better solution to designing an HTML calendar than Flex because the grid gives you better control over cell placement.

Flex Calendar CSS Code

<style>
/ Flex calendar's container/
#calendar {
    display: flex;
    flex-wrap: wrap;
    width: 100%;
    height: auto;
}

/ Calendar's flex cell /
#calendar div {
    font-size: 28px;
    font-weight: bold;
    border-radius: 8px;
    min-width: 100px;
    line-height: 100px;
    height: 100px;
    text-align: center;
    margin: 5px;
}

/ Days have a yellow background /
#calendar .day {
    background-color: #fffa69;
}
</style>

Flex calendar HTML scaffold

<div id = "calendar">
    <!-- use empty divs to create empty cells -->
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <!-- Flex calendar starts here -->
    <div class = "day">1</div>
    <div class = "day">2</div>
    <div class = "day">3</div>
    <div class = "day">4</div>
    <div class = "day">5</div>
    <div class = "day">6</div>
    <div class = "day">7</div>
    <div class = "day">8</div>
    <div class = "day">9</div>
    <div class = "day">10</div>
    <div class = "day">11</div>
    <div class = "day">12</div>
    <div class = "day">13</div>
    <div class = "day">14</div>
    <div class = "day">15</div>
    <div class = "day">16</div>
    <div class = "day">17</div>
    <div class = "day">18</div>
    <div class = "day">19</div>
    <div class = "day">20</div>
    <div class = "day">21</div>
    <div class = "day">22</div>
    <div class = "day">23</div>
    <div class = "day">24</div>
    <div class = "day">25</div>
    <div class = "day">26</div>
    <div class = "day">27</div>
    <div class = "day">28</div>
    <div class = "day">29</div>
    <div class = "day">30</div>
    <div class = "day">31</div>
</div>

(Help spread the word about this article)

Share link to this article on your social media.

viewed 1.9K times
› tutorials › css › flex calendar
Write For Us
Sign Up Now  -  It's Free!

CSS Flex Calendar

Comments (2) New! (You can now post comments on articles!)

(By posting a comment you are registering a Ghost Together account.)
Register
Register
Post It
DM Coming Soon
f f