<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="https://shkspr.mobi/blog/wp-content/themes/edent-wordpress-theme/rss-style.xsl" type="text/xsl"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	    xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	     xmlns:dc="http://purl.org/dc/elements/1.1/"
	   xmlns:atom="http://www.w3.org/2005/Atom"
	     xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	  xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>
<channel>
	<title>flexbox &#8211; Terence Eden’s Blog</title>
	<atom:link href="https://shkspr.mobi/blog/tag/flexbox/feed/" rel="self" type="application/rss+xml" />
	<link>https://shkspr.mobi/blog</link>
	<description>Regular nonsense about tech and its effects 🙃</description>
	<lastBuildDate>Mon, 28 Apr 2025 08:43:54 +0000</lastBuildDate>
	<language>en-GB</language>
	<copyright>© Terence Eden. 🄯 CC BY-SA. See https://shkspr.mobi/blog/copyright-and-copyleft/</copyright>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.1.3</generator>

<image>
	<url>https://shkspr.mobi/blog/wp-content/uploads/2023/07/cropped-avatar-32x32.jpeg</url>
	<title>flexbox &#8211; Terence Eden’s Blog</title>
	<link>https://shkspr.mobi/blog</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title><![CDATA[Responsive Yearly Calendar with Flexbox]]></title>
		<link>https://shkspr.mobi/blog/2023/04/responsive-yearly-calendar-with-flexbox/</link>
					<comments>https://shkspr.mobi/blog/2023/04/responsive-yearly-calendar-with-flexbox/#comments</comments>
				<dc:creator><![CDATA[Terence Eden]]></dc:creator>
		<pubDate>Fri, 28 Apr 2023 11:34:47 +0000</pubDate>
		<category><![CDATA[CSS]]></category><category><![CDATA[flexbox]]></category><category><![CDATA[HTML5]]></category><category><![CDATA[responsive]]></category>		<guid isPermaLink="false">https://shkspr.mobi/blog/?p=45646</guid>

					<description><![CDATA[This blog has a calendar showing my yearly archives. It was in a table layout - which made sense when I first designed it - but had a few spacing niggles and was hard to make responsive.  Now, it behaves like this:    The code is relatively straightforward.  The HTML for the calendar looks like this:  &#60;div class=&#34;calendars&#34;&#62;     &#60;div class=&#34;calendar&#34;&#62;         &#60;div class=&#34;calendar-year&#34;&#62;2018&#60;/div&#62; …]]></description>
										<content:encoded>&lt;p&gt;This blog has a calendar showing my yearly archives. It was in a table layout - which made sense when I first designed it - but had a few spacing niggles and was hard to make responsive.&lt;/p&gt;

&lt;p&gt;Now, it behaves like this:&lt;/p&gt;

&lt;p&gt;&lt;video width="1024" height="576" src="https://shkspr.mobi/blog/wp-content/uploads/2023/04/Responsive-Calendar.mp4" mute="" loop="" autoplay=""&gt;&lt;/video&gt;&lt;/p&gt;

&lt;p&gt;The code is relatively straightforward.  The HTML for the calendar looks like this:&lt;/p&gt;

&lt;pre&gt;&lt;code class="language-html"&gt;&amp;lt;div class="calendars"&amp;gt;
    &amp;lt;div class="calendar"&amp;gt;
        &amp;lt;div class="calendar-year"&amp;gt;2018&amp;lt;/div&amp;gt;
        &amp;lt;div class="calendar-month"&amp;gt;January&amp;lt;/div&amp;gt;
        &amp;lt;div class="calendar-month"&amp;gt;February&amp;lt;/div&amp;gt;
        &amp;lt;div class="calendar-month"&amp;gt;March&amp;lt;/div&amp;gt;
        &amp;lt;div class="calendar-month"&amp;gt;April&amp;lt;/div&amp;gt;
        &amp;lt;div class="calendar-month"&amp;gt;May&amp;lt;br&amp;gt;&amp;lt;/div&amp;gt;
        &amp;lt;div class="calendar-month"&amp;gt;June&amp;lt;/div&amp;gt;
        &amp;lt;div class="calendar-month"&amp;gt;July&amp;lt;/div&amp;gt;
        &amp;lt;div class="calendar-month"&amp;gt;August&amp;lt;/div&amp;gt;
        &amp;lt;div class="calendar-month"&amp;gt;September&amp;lt;/div&amp;gt;
        &amp;lt;div class="calendar-month"&amp;gt;October&amp;lt;/div&amp;gt;
        &amp;lt;div class="calendar-month"&amp;gt;November&amp;lt;/div&amp;gt;
        &amp;lt;div class="calendar-month"&amp;gt;December&amp;lt;/div&amp;gt;
    &amp;lt;/div&amp;gt;

    &amp;lt;div class="calendar"&amp;gt;
        &amp;lt;div class="calendar-year"&amp;gt;2017&amp;lt;/div&amp;gt;
        &amp;lt;div class="calendar-month"&amp;gt;January&amp;lt;/div&amp;gt;
        &amp;lt;div class="calendar-month"&amp;gt;February&amp;lt;/div&amp;gt;
                ...
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Repeat as many times as needed.&lt;/p&gt;

&lt;p&gt;The CSS is slightly more tricky, but mercifully short:&lt;/p&gt;

&lt;p&gt;The wrapper which holds all the calendars uses &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/flex-wrap"&gt;&lt;code&gt;flex-wrap&lt;/code&gt;&lt;/a&gt;. This means there's no need to set explicit breakpoints - if there's no horizontal space, the calendar will move to the next row.&lt;/p&gt;

&lt;pre&gt;&lt;code class="language-css"&gt;.calendars {
    display: flex;
    flex-wrap: wrap;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Each individual calendar item is &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/grid-template-columns"&gt;a grid with three column layout&lt;/a&gt;:&lt;/p&gt;

&lt;pre&gt;&lt;code class="language-css"&gt;.calendar {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    margin: .5em;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The "Year" at the top spans the first three columns. I find the &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/grid-column-end"&gt;&lt;code&gt;grid-column-...&lt;/code&gt; syntax&lt;/a&gt; confusing!&lt;/p&gt;

&lt;pre&gt;&lt;code class="language-css"&gt;.calendar-year {
    grid-column-start: 1;
    grid-column-end: 4;
    text-align: center;
    outline: 1px black solid;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Finally, each individual month has a bit of internal padding and text formatting:&lt;/p&gt;

&lt;pre&gt;&lt;code class="language-css"&gt;.calendar-month {
    text-align: center;
    padding: .25em;
    outline: 1px black solid;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;I've used a basic black &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/outline"&gt;&lt;code&gt;outline&lt;/code&gt;&lt;/a&gt;. Obviously, you can add whatever fancy CSS you like to make them look prettier.&lt;/p&gt;
&lt;img src="https://shkspr.mobi/blog/wp-content/themes/edent-wordpress-theme/info/okgo.php?ID=45646&amp;amp;HTTP_REFERER=RSS" alt="" width="1" height="1" loading="eager"&gt;</content:encoded>
					
					<wfw:commentRss>https://shkspr.mobi/blog/2023/04/responsive-yearly-calendar-with-flexbox/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		<enclosure url="https://shkspr.mobi/blog/wp-content/uploads/2023/04/Responsive-Calendar.mp4" length="117070" type="video/mp4" />

			</item>
	</channel>
</rss>
