<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>That Emil - Blog</title><link>https://thatemil.com/blog/</link><description>Blog posts from Emil Björklund.</description><atom:link rel="self" href="https://thatemil.com/blog/rss"></atom:link><language>en-us</language><lastBuildDate>Fri, 16 Jan 2026 17:19:59 +0000</lastBuildDate><item><title>CSS Specificity as semantic versioning</title><link>https://thatemil.com/blog/2020/09/11/css-specificity-semver/</link><description>


&lt;div style="font-weight:700"&gt;

&lt;p&gt;When thinking about CSS specificity, it can be tricky at first to understand how one selector beats another. It just occurred to me that &lt;em&gt;semantic versioning&lt;/em&gt; could be a good way to explain it.&lt;/p&gt;

&lt;/div&gt;

&lt;p&gt;&lt;a href="https://semver.org/"&gt;Semantic versioning&lt;/a&gt; is, of course, another slightly complex topic that someone beginning in the web dev world may or may not be familliar with, but bear with me here for a little bit.&lt;/p&gt;

&lt;p&gt;The &lt;a href="https://www.w3.org/TR/selectors-3/#specificity"&gt;CSS spec for selector specificity&lt;/a&gt; states that each value is represented with an unspecified ”large base”, so for example 10 class name selectors will not make the number ”tick over” and equal 1 ID-selector, as it would in a base-10 system.&lt;/p&gt;

&lt;p&gt;If we disregard the ”semantic” bit of semantic versioning, and stick to the major-minor-patch format, they work in the same way: version 1.9.9 does not tick over to 2.0.0 whenever a patch is released – the unspecified base means it would become 1.9.10 instead. In CSS specificity, higher version numbers simply beat lower ones.&lt;/p&gt;

&lt;p&gt;I got the idea when reading &lt;a href="https://lea.verou.me/2020/09/parsel-a-tiny-permissive-css-selector-parser/"&gt;Lea Verou’s post on Parsel&lt;/a&gt; – and the way the specificity is shown in the UI there (&lt;code&gt;1,5,1&lt;/code&gt;), which was familliar to me from other places as well. Maybe the ”version-number-syntax” of &lt;code&gt;1.5.1&lt;/code&gt; could be an alternative way of teaching – at least maybe better than the &lt;code&gt;151&lt;/code&gt; format used in the spec.&lt;/p&gt;

</description><guid>https://thatemil.com/blog/2020/09/11/css-specificity-semver/</guid></item><item><title>Custom properties for breakpoint debugging</title><link>https://thatemil.com/blog/2018/02/23/custom-properties-breakpoint-debugging/</link><description>


&lt;div style="font-weight:700"&gt;

&lt;p&gt;Yesterday, I stumbled across Eric Meyer’s post on &lt;a href="https://meyerweb.com/eric/thoughts/2018/02/21/displaying-css-breakpoint-information-with-generated-content/"&gt;displaying CSS breakpoint information with generated content&lt;/a&gt;. It reminded me of a solution to a related problem that Jeremy Keith blogged about way back in 2012 – &lt;a href="https://adactio.com/journal/5414"&gt;how to conditionally load content&lt;/a&gt; (via JavaScript) when a certain breakpoint is active.&lt;/p&gt;

&lt;/div&gt;

&lt;p&gt;I was one of the people who came up with a potential &lt;a href="https://adactio.com/journal/5429"&gt;solution to Jeremy’s problem&lt;/a&gt;, &lt;a href="https://gist.github.com/emilbjorklund/2481019"&gt;using pseudo-elements to stash a bit of text&lt;/a&gt; on (for example) the &lt;code&gt;body&lt;/code&gt; element, and then reading that data via JS, using &lt;code&gt;window.getComputedStyle(el, '::after')&lt;/code&gt; etc.&lt;/p&gt;

&lt;p&gt;It was a hack, but it definitely worked.&lt;/p&gt;

&lt;p&gt;Eric has discovered pretty much the exact same solution, but instead of hiding the stashed piece of text, he’s showing it to get a visual clue as to which media query (out of a few possible candidates) is currently active. Smart!&lt;/p&gt;

&lt;p&gt;Now to the fun part: I remember having a discussion with Jeremy at some point about how the proper way to communicate in this manner between CSS &amp;amp; JS would be Custom Properties. &lt;a href="https://thatemil.com/blog/2013/12/15/playing-around-with-css-variables-custom-properties/"&gt;I blogged about that back in 2013&lt;/a&gt;, using the Media Query naming technique as an example.&lt;/p&gt;

&lt;p&gt;The solution I proposed there makes perfect sense as a small improvement to Eric’s debugging trick. Using a custom property allows for much cleaner code when setting the ”named breakpoint” text.&lt;/p&gt;

&lt;pre&gt;&lt;code class="language-css"&gt;body::after {
   content: var(--bp, 'narrow');
}

@media (min-width: 25em) {
  :root {--bp: '&gt;=25em'}
}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The first use of the &lt;code&gt;var()&lt;/code&gt; uses a fallback value that you can pass in if the &lt;code&gt;--bp&lt;/code&gt; custom property is undefined in the current scope. Then, at each increasingly wide breakpoint, you could update the &lt;code&gt;--bp&lt;/code&gt; value to something new.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://jsbin.com/vadeleg/3"&gt;I’ve put a quick demo on JSBin&lt;/a&gt; – wrapped in one of my favorite CSS one-liners which I first saw from &lt;a href="https://lea.verou.me/"&gt;Lea Verou&lt;/a&gt; (although I can’t remember exactly where):&lt;/p&gt;

&lt;pre&gt;&lt;code class="language-css"&gt;@supports (--css: variables) {}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Ah, blogging. Not dead yet.&lt;/p&gt;

</description><guid>https://thatemil.com/blog/2018/02/23/custom-properties-breakpoint-debugging/</guid></item><item><title>Progressive Web Apps behind Basic Auth</title><link>https://thatemil.com/blog/2018/02/21/pwa-basic-auth/</link><description>


&lt;div style="font-weight:700"&gt;

&lt;p&gt;When adding a service worker and Web App Manifest to a staging site recently, I ran into some small issues with HTTP Basic Auth. Here's how I solved them.&lt;/p&gt;

&lt;/div&gt;

&lt;p&gt;I know, I know. HTTP Basic Auth is soooo lame. Yet, I still use it for secret-but-not-super-secret stuff that I want to test out on a server reachable from the public web.&lt;/p&gt;

&lt;p&gt;When combining it with a &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API"&gt;service worker&lt;/a&gt; and &lt;a href="https://developer.mozilla.org/en-US/docs/Web/Manifest"&gt;Web App Manifest&lt;/a&gt;, I ran into some issues. I've resolved most of them, but I thought I'd document my findings here mostly for myself, and update as I go along.&lt;/p&gt;

&lt;p&gt;Caveat: I need to research if these are good to place there regardless of environment, or if they should be removed in production. Also, I'm still having issues with the authentication dialog not showing up unless I pop open devtools, so I probably need to be adding credentials in more places to have it working 100%.&lt;/p&gt;

&lt;h2&gt;Adding items to cache – add credentials&lt;/h2&gt;

&lt;p&gt;If you have calls that look like this:&lt;/p&gt;

&lt;pre class="code-block"&gt;&lt;code class="lang-javascript"&gt;cache.addAll([
        /* some files */
      ]);&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;...you’ll need to add credentials to those Request objects:&lt;/p&gt;

&lt;pre class="code-block"&gt;&lt;code class="lang-javascript"&gt;cache.addAll([
        /* some files */
      ].map(url =&gt; new Request(url, {credentials: 'same-origin'})));&lt;/code&gt;&lt;/pre&gt;

&lt;h2&gt;Credentials for Web App Manifest&lt;/h2&gt;

&lt;p&gt;The same logic goes for your &lt;code&gt;manifest.json&lt;/code&gt; file: it needs to pass on credentials, and it doesn't by default.&lt;/p&gt;

&lt;p&gt;The fix here is simpler: you need to add the &lt;code&gt;crossorigin&lt;/code&gt; attribute to the &lt;code&gt;link&lt;/code&gt;-tag:&lt;/p&gt;

&lt;pre class="code-block"&gt;&lt;code class="lang-html"&gt;&amp;lt;link rel=&amp;quot;manifest&amp;quot; href=&amp;quot;/manifest.json&amp;quot; crossorigin=&amp;quot;use-credentials&amp;quot;&amp;gt;&lt;/code&gt;&lt;/pre&gt;

</description><guid>https://thatemil.com/blog/2018/02/21/pwa-basic-auth/</guid></item><item><title>Smart borders between flex items – the dumb way</title><link>https://thatemil.com/blog/2018/01/08/direction-independent-borders-this-is-stupid/</link><description>


&lt;div style="font-weight:700"&gt;

&lt;p&gt;Caution, stupid code ahead.&lt;/p&gt;

&lt;/div&gt;

&lt;p&gt;When creating a component that adapts to available space without using Media Queries, I found myself in a situation where I had two items and wanted a border between them, regardless if they were side by side or on top of one another. The border would be left (or right) when items lined up horizontally, but top (or bottom) when the items lined up vertically.&lt;/p&gt;

&lt;p&gt;In essence, I wanted &lt;code&gt;border-between&lt;/code&gt; or somesuch property to exist.&lt;/p&gt;

&lt;p&gt;With a little fiddling and some brain ping-pong with &lt;a href="http://www.robinwhittleton.com/"&gt;Robin&lt;/a&gt;, I came up with the following solution:&lt;/p&gt;

&lt;p data-height="137" data-theme-id="0" data-slug-hash="MrrJyZ" data-default-tab="result" data-user="thatemil" data-embed-version="2" data-pen-title="MrrJyZ" class="codepen"&gt;&lt;a href="https://codepen.io/thatemil/pen/MrrJyZ/"&gt;CodePen example&lt;/a&gt;&lt;/p&gt;

&lt;script async src="https://production-assets.codepen.io/assets/embed/ei.js"&gt;&lt;/script&gt;

&lt;pre class="code-block"&gt;&lt;code class="lang-css"&gt;.container {
  display: flex;
  flex-wrap: wrap;
  overflow: hidden;
}

.item {
  flex: 1 1 20em;
  background-color: hotpink;
  border-top: 1px solid purple;
  border-left: 1px solid purple;
  margin-top: -1px;
  margin-left: -1px;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;...where the border is always present on top/left, but hidden with negative margins. Ouch. Caveats: lots, probably. Not least that this only works (nicely) in a pretty limited set of circumstances.&lt;/p&gt;

&lt;p&gt;Then, I thought, ”wait, I could just use the &lt;a href="https://drafts.csswg.org/css-logical/"&gt;logical direction keywords&lt;/a&gt; (&lt;code&gt;border-block-start&lt;/code&gt; vs &lt;code&gt;border-inline-start&lt;/code&gt; etc) in modern browsers”, quickly followed by, ”no, I can’t – the logical direction isn’t actually changing.” Oh well.&lt;/p&gt;

&lt;p&gt;Current status: feeling clever/feeling dirty.&lt;/p&gt;

</description><guid>https://thatemil.com/blog/2018/01/08/direction-independent-borders-this-is-stupid/</guid></item><item><title>Fixing fieldsets</title><link>https://thatemil.com/blog/2017/07/01/fixing-fieldsets/</link><description>


&lt;div style="font-weight:700"&gt;

&lt;p&gt;The &lt;code&gt;fieldset&lt;/code&gt; element is a really useful one. It creates a grouping of related form fields, giving them a label in the shape of a &lt;code&gt;legend&lt;/code&gt; element.&lt;/p&gt;

&lt;p&gt;Sadly, people have been avoiding the fieldset element. Purely for lack of styling options (or reluctance to add &lt;a href="https://thatemil.com/blog/2015/01/03/reset-your-fieldset/"&gt;a mess of hacky CSS&lt;/a&gt;), this semantically clear and accessibility-enhancing element has been ignored since forever.&lt;/p&gt;

&lt;/div&gt;

&lt;p&gt;The appearance of a fieldset and its associated legend is more or less hardcoded into the browser, and it acts more like replaced content than the simple container and text pairing that it is. The &lt;a href="https://html.spec.whatwg.org/multipage/rendering.html#the-fieldset-and-legend-elements"&gt;HTML spec&lt;/a&gt; has formalized these wierdnesses, and dictates some rather odd behaviors of how the &lt;code&gt;fieldset&lt;/code&gt; and &lt;code&gt;legend&lt;/code&gt; combo is to be rendered:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;A fieldset element's rendered legend, if any, is expected to be rendered over the block-start border edge of the fieldset element as a block box (overriding any explicit 'display' value).&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;I think it's about time that we fix this. I also think that browser makers and spec writers have a unique opportunity to implement that fix at this moment in history.&lt;/p&gt;

&lt;p&gt;Enter &lt;code&gt;display: contents&lt;/code&gt;. This declaration basically &lt;a href="https://rachelandrew.co.uk/archives/2016/01/29/vanishing-boxes-with-display-contents/"&gt;tells the browser to not generate a rendered box for the element to which it is applied&lt;/a&gt;. Currently, it &lt;a href="https://github.com/whatwg/html/issues/2756"&gt;does not work on &amp;lt;code&amp;gt;fieldset&amp;lt;/code&amp;gt; elements where supported&lt;/a&gt; - but I think it should. When chatting to &lt;a href="https://adactio.com"&gt;Jeremy&lt;/a&gt; about this, he said it sounded like "a DOCTYPE switch for fieldset rendering", which I think is spot on.&lt;/p&gt;

&lt;p&gt;The legacy appearance of fieldsets probably needs to be preserved for compatibility reasons. But &lt;code&gt;display: contents&lt;/code&gt; is not supported in any old browsers, and is most likely used on exactly zero sites using the legacy look of fieldsets. If it &lt;em&gt;is&lt;/em&gt; applied, the legend should probably just become an inline element, and it would be up to authors to style it any way they see fit.&lt;/p&gt;

&lt;p&gt;So: browser makers should allow authors to set &lt;code&gt;display: contents&lt;/code&gt; on &lt;code&gt;fieldset&lt;/code&gt; elements, thus removing all of the associated weird handling of backgrounds and borders, and weird positioning of legend elements inside them. Should a wrapper element for the fieldset be needed, authors can add a &lt;code&gt;div&lt;/code&gt; or other element. The spec should allow for this exception - I've opened issues against the &lt;a href="https://github.com/whatwg/html/issues/2805"&gt;WHATWG spec&lt;/a&gt; as well as the &lt;a href="https://github.com/w3c/html/issues/957"&gt;W3C HTML spec&lt;/a&gt;, and I hope that's at least a start to get the ball rolling.&lt;/p&gt;

&lt;p&gt;Come on, people – let's fix this.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Update&lt;/strong&gt;: it seems that &lt;a href="https://drafts.csswg.org/css-display/#unbox-html"&gt;the CSS Display spec actually has an appendix describing this very situation&lt;/a&gt;, and that &lt;code&gt;display: contents&lt;/code&gt; should remove &lt;cite&gt;magic display behavior&lt;/cite&gt; from &lt;code&gt;legend&lt;/code&gt; elements specifically when it is applied. In which case, the spec authors deserve a break, and bugs will have to be opened agains browser implementations instead. Specifically, Chrome (Canary, with experimental web features flag enabled) gets it right on &lt;code&gt;fieldset&lt;/code&gt; but not &lt;code&gt;legend&lt;/code&gt;, and Firefox disregards it completetly. I've put up a &lt;a href="https://codepen.io/thatemil/details/bRMJmE/"&gt;quick test on Codepen&lt;/a&gt;.&lt;/p&gt;

</description><guid>https://thatemil.com/blog/2017/07/01/fixing-fieldsets/</guid></item><item><title>Enquire Within Upon @media</title><link>https://thatemil.com/blog/2016/06/20/enquire-within-upon-media/</link><description>


&lt;div style="font-weight:700"&gt;

&lt;p&gt;When dealing with advanced layout features, it makes sense to place all of your CSS inside of a feature query, including media queries for the advanced layout. However, Chrome (currently) drops the ball on that last bit. &lt;ins&gt;The Chrome bug has since been fixed, so it should hopefully work better in coming versions&lt;/ins&gt;.&lt;/p&gt;

&lt;/div&gt;

&lt;p&gt;&lt;a href="https://thatemil.com/blog/2015/06/30/grid-tidbits-1-why-where/"&gt;Grid Layout&lt;/a&gt; will soon be available in browsers. With it comes a classic conundrum – &lt;a href="http://caniuse.com/#search=grid%20layout"&gt;when can we use it&lt;/a&gt;?&lt;/p&gt;

&lt;p&gt;As Grid very much defines what is possible in terms of CSS layout, it's likely that adoption will initially be a little slow, at least for existing sites. For newly created web properties, I'd advocate an &lt;a href="https://twitter.com/zeldman/status/466260364897038336"&gt;”aggresive enhancement”&lt;/a&gt; approach as soon as support is reasonably wide. What I mean by that is make your layout as simple as possible for simpler browsers (a single column, maybe some small flexbox, inline-block or float enhancements here and there), but bring out the Big Grid Guns when supported.&lt;/p&gt;

&lt;p&gt;Using this strategy, you'd probably want to make sure that the code for the Grid-based layout is properly isolated. Something like this would be a good starting point:&lt;/p&gt;

&lt;pre class="code-block"&gt;&lt;code class="lang-css"&gt;@supports (display: grid) {
  /* KABOOM! */
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Given this approach, you probably want your &lt;code&gt;@media&lt;/code&gt; rules for the fancy responsive goodness inside the &lt;code&gt;@supports&lt;/code&gt; rule. And this is all fine, according to the spec.&lt;/p&gt;

&lt;p&gt;However, at the time of writing, Chrome does not respond dynamically to &lt;code&gt;@media&lt;/code&gt; rules inside &lt;code&gt;@supports&lt;/code&gt; rules – it reacts at page load, but not on window resize. Other browsers I’ve tested (Firefox, Safari) handle this just fine. Not a show stopper, but it got me scratching my head for a while. I’ve &lt;a href="https://bugs.chromium.org/p/chromium/issues/detail?id=621502"&gt;filed a bug&lt;/a&gt; &lt;ins&gt;and this has since been fixed – should be out in a version or two (52+?)&lt;/ins&gt;.&lt;/p&gt;

&lt;p&gt;In conclusion, this will currently not be triggered correctly on window resize in Chrome:&lt;/p&gt;

&lt;pre class="code-block"&gt;&lt;code class="lang-css"&gt;@supports (display: grid) {
  @media (min-width: 65em) {
     /* ...sad trombone */
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;...but this will:&lt;/p&gt;

&lt;pre class="code-block"&gt;&lt;code class="lang-css"&gt;@media (min-width: 65em) {
  @supports (display: grid) {
     /* ...mildly amused trombone */
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;(If you're wondering about the title, it is a reference to the precursor to the World Wide Web, which Sir Tim called &lt;a href="https://en.wikipedia.org/wiki/ENQUIRE"&gt;ENQUIRE&lt;/a&gt;, after a book called &lt;a href="https://en.wikipedia.org/wiki/Enquire_Within_Upon_Everything"&gt;&lt;em&gt;Enquire Within Upon Everything&lt;/em&gt;&lt;/a&gt;.)&lt;/p&gt;

</description><guid>https://thatemil.com/blog/2016/06/20/enquire-within-upon-media/</guid></item><item><title>Revisiting the Float Label pattern with CSS</title><link>https://thatemil.com/blog/2016/01/23/floating-label-no-js-pure-css/</link><description>


&lt;div style="font-weight:700"&gt;

&lt;p&gt;The &lt;a href="http://mds.is/float-label-pattern/"&gt;float label pattern&lt;/a&gt; is a slick pattern that designers seem to love. I’m not sure that I’m 100% in love with it, but I couldn't resist cooking up a quick demo implementation. This version uses a few nice form-styling tricks using modern CSS that I've seen recently, particularly the &lt;code&gt;:placeholder-shown&lt;/code&gt; selector.&lt;/p&gt;

&lt;/div&gt;

&lt;p&gt;First things first: this is &lt;strong&gt;not&lt;/strong&gt; a ”Best practice” implementation in any way, shape or form. It works in recent versions of some  browsers — most notably Chrome/Opera and Safari/WebKit. It fails miserably in Firefox. I have barely tested it. Be warned.&lt;/p&gt;

&lt;p&gt;I'm relying on quite a few moving parts here:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Flexbox—using &lt;a href="http://codepen.io/HugoGiraudel/pen/b3274eb0bf93bed79afeafd30b7a33f1"&gt;Hugo Giraudel’s pattern&lt;/a&gt; for putting the label after the input in the markup, then reversing the order.&lt;/li&gt;
&lt;li&gt;A &lt;code&gt;transform&lt;/code&gt; to shift the &lt;code&gt;label&lt;/code&gt; down over the input. When this state is active, the placeholder text get's an &lt;code&gt;opacity: 0&lt;/code&gt; so the two pieces of text don’t overlap.&lt;/li&gt;
&lt;li&gt;Shifting the &lt;code&gt;label&lt;/code&gt; up only when the placeholder is &lt;em&gt;not&lt;/em&gt; shown, i.e. when the field is filled in, or when it’s focused, inspired by &lt;a href="https://adactio.com/journal/10000"&gt;Jeremy’s ”Pseudon’t” post&lt;/a&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;That last part is what separates this implementation from for example &lt;a href="http://css-tricks.com/float-labels-css/"&gt;Chris Coyier’s&lt;/a&gt; and  &lt;a href="http://snook.ca/archives/html_and_css/floated-label-pattern-css"&gt;Jonathan Snook’s&lt;/a&gt; versions, in that they use the &lt;code&gt;:valid&lt;/code&gt; pseudo-class. I think this demo steps around that particular limitation, but as I said at the start, there are limitations in the form of browser support.&lt;/p&gt;

&lt;p&gt;This version instead uses the &lt;code&gt;:placeholder-shown&lt;/code&gt; pseudo-class, but negated to only move the label out of the way when the placeholder text is not showing—which plays nicely with how the pattern is supposed to work.&lt;/p&gt;

&lt;p&gt;Here's the relevant HTML:&lt;/p&gt;

&lt;pre class="code-block"&gt;&lt;code class="lang-markup"&gt;&amp;lt;div class="field"&amp;gt;
    &amp;lt;input type="text" name="fullname" id="fullname" placeholder="Jane Appleseed"&amp;gt;
    &amp;lt;label for="fullname"&gt;Name&amp;lt;/label&amp;gt;
&amp;lt;/div&amp;gt;&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;...and the CSS:&lt;/p&gt;

&lt;pre class="code-block"&gt;&lt;code class="lang-css"&gt;/**
* Make the field a flex-container, reverse the order so label is on top.
*/
.field {
  display: flex;
  flex-flow: column-reverse;
}
/**
* Add a transition to the label and input.
*/
label, input {
  transition: all 0.2s;
}

input {
  font-size: 1.5em;
  border: 0;
  border-bottom: 1px solid #ccc;
}
/**
* Change input border on focus.
*/
input:focus {
  outline: 0;
  border-bottom: 1px solid #666;
}
/**
* When the label follows an input matching :placeholder-shown...
* 1. Make sure the label is only on one row, at max 2/3rds of the
*     field—to make sure it scales properly and doesn't wrap.
* 2. Fix the cursor.
* 3. Translate down and scale the label up to cover the placeholder.
*/
input:placeholder-shown label {
  /* [1] */
  max-width: 66.66%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  /* |2] */
  cursor: text;
  /* [3 */
  transform-origin: left bottom; 
  transform: translate(0, 2.125rem) scale(1.5);
}
/**
* By default, the placeholder should be transparent. Also, it should 
* inherit the transition.
*/
::-webkit-input-placeholder {
  transition: inherit;
  opacity: 0;
}
/**
* Show the placeholder when the input is focused.
*/
input:focus::-webkit-input-placeholder {
  opacity: 1;
}
/**
* 1. When the element is focused, remove the label transform.
*     Also, do this when the placeholder is _not_ shown, i.e. when 
*     there's something in the input at all.
* 2. ...and set the cursor to pointer.
*/
input:not(:placeholder-shown) + label,
input:focus + label {
  transform: translate(0, 0) scale(1); /* [1] */
  cursor: pointer; /* [2] */
}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;&lt;strong&gt;Update 2016-01-26:&lt;/strong&gt; I updated the selector for the label so that the transformed label is only used when it's following an input matching &lt;code&gt;:placeholder-shown&lt;/code&gt;. That way, non-supporting browsers fall back to the ”normal” label-above-the-input pattern. Thanks to &lt;a href="https://twitter.com/mattecapu/"&gt;Matteo Capucci&lt;/a&gt; for pointing out that simple enhancement to me—in my haste to whip up the demo, I completely missed that simple improvement. Also thanks to &lt;a href="https://twitter.com/patchhofweber"&gt;Patch&lt;/a&gt; for pointing out the &lt;code&gt;cursor:pointer&lt;/code&gt;-improvement.&lt;/p&gt;

&lt;p&gt;Here's the full &lt;a href="http://jsbin.com/pagiti/11/edit?html,css,output"&gt;JSBin demo&lt;/a&gt;.&lt;/p&gt;

</description><guid>https://thatemil.com/blog/2016/01/23/floating-label-no-js-pure-css/</guid></item><item><title>Grid Tidbits part 3: grid track sizing</title><link>https://thatemil.com/blog/2015/08/24/grid-tidbits-3-track-sizing/</link><description>


&lt;div style="font-weight:700"&gt;

&lt;p&gt;This post will examine some of the finer points of sizing grid tracks (a.k.a. rows and columns) in CSS Grid Layout. Flexible sizing, the repeater function, the minmax function – oh my!&lt;/p&gt;

&lt;/div&gt;

&lt;aside class="entry-aside"&gt;

&lt;p&gt;This is the third post in a series of reasonably short pieces on Grid Layout. &lt;a href="/blog/2015/06/30/grid-tidbits-1-why-where/"&gt;Part 1 goes over the why and where&lt;/a&gt;, &lt;a href="/blog/2015/07/12/grid-tidbits-2-terminology-basics/"&gt;part 2 goes over the terminology and basics&lt;/a&gt;.&lt;/p&gt;

&lt;/aside&gt;

&lt;p&gt;To play along with the examples in this post, I recommend that you download and fire up Chrome Canary, since that browser has the most up-to-date implementation.&lt;/p&gt;

&lt;h2&gt;Recap&lt;/h2&gt;

&lt;p&gt;In the previous tidbit, we used some very simple markup to represent a grid container and three child items.&lt;/p&gt;

&lt;pre class="code-block"&gt;&lt;code class="language-markup"&gt;&amp;lt;div class="grid-container"&amp;gt;
  &amp;lt;div class="grid-item-a"&amp;gt;A&amp;lt;/div&amp;gt;
  &amp;lt;div class="grid-item-b"&amp;gt;B&amp;lt;/div&amp;gt;
  &amp;lt;div class="grid-item-c"&amp;gt;C&amp;lt;/div&amp;gt;
&amp;lt;/div&amp;gt;&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;We're going to keep this markup, but play with the sizing. The grid track definitions we started with looked like this:&lt;/p&gt;

&lt;pre class="code-block"&gt;&lt;code class="language-css"&gt;.grid-container {
  display: grid;
  grid-template-columns: 50% 50%;
  grid-template-rows: auto auto;
}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The above means we created a 2 ✕ 2 grid template, where the two columns each take up 50% of the width, and the two rows automatically adjust their height to fit the tallest content inside. If we just let the items position themselves with the automatic placement algorithm, A and B end up in the first row, and C ends up in the bottom left corner. &lt;/p&gt;

&lt;figure&gt;

&lt;p&gt;&lt;img src="/media/attachments/grid-auto.png" alt="A two by two grid with three items (labelled A,B,C), two on the first row and one on the second." /&gt;&lt;/p&gt;

&lt;figcaption markdown="-1"&gt;The 2 ✕ 2 grid from part 2 (&lt;a href="http://jsbin.com/naxaxe/1/edit?html,css,output"&gt;JSBin link for figure 1&lt;/a&gt;)&lt;/figcaption&gt;

&lt;/figure&gt;

&lt;p&gt;The mental shift to understand grid layout is that the sizing mechanics of the grid resides mostly in the grid track definitions, rather than in the items themselves. We can use loads of types of measurements to size tracks – percentages, ems, pixels, viewport units etc. But there are more exciting possibilities in the grid layout spec – let’s jump straight in!&lt;/p&gt;

&lt;h2&gt;Getting flexible – the &lt;code&gt;fr&lt;/code&gt;-unit&lt;/h2&gt;

&lt;p&gt;The Grid Layout spec introduces a new unit for flexible sizing. The &lt;code&gt;fr&lt;/code&gt; unit stands for &lt;em&gt;fraction of remaining space&lt;/em&gt;. It distributes the space left when any tracks sized with &lt;code&gt;auto&lt;/code&gt;, percentages, &lt;code&gt;em&lt;/code&gt;s, pixels etc have been calculated. If you know your flexbox, it's basically the same thing as a &lt;code&gt;flex-grow&lt;/code&gt; factor, with a &lt;code&gt;0&lt;/code&gt; &lt;code&gt;flex-basis&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;If we change the first column to be &lt;code&gt;5em&lt;/code&gt; and the second column to be &lt;code&gt;1fr&lt;/code&gt;, the second column will receive any space left above &lt;code&gt;5em&lt;/code&gt;.&lt;/p&gt;

&lt;pre class="code-block"&gt;&lt;code class="language-css"&gt;.grid-container {
  display: grid;
  grid-template-columns: 5em 1fr;
  grid-template-rows: auto auto;
}&lt;/code&gt;&lt;/pre&gt;

&lt;figure&gt;

&lt;p&gt;&lt;img src="/media/attachments/grid-1fr.png" alt="The two by two grid, where the left column is narrower than the right" /&gt;&lt;/p&gt;

&lt;figcaption markdown="-1"&gt;The updated grid, where the right column takes up any space left above the 5em width of the left column. (&lt;a href="http://jsbin.com/naxaxe/2/edit?html,css,output"&gt;JSBin link for figure 2&lt;/a&gt;)&lt;/figcaption&gt;

&lt;/figure&gt;

&lt;p&gt;You may be wondering what the &lt;code&gt;1&lt;/code&gt; in &lt;code&gt;1fr&lt;/code&gt; actually stands for. If you’re comfortable with flexbox already, you may have a reasonably clear picture, but it doesn’t hurt to actually get into the details.&lt;/p&gt;

&lt;p&gt;For example, what happens if the right column would be sized to &lt;code&gt;2fr&lt;/code&gt;? Would it then be two times as wide as the remaining space, and cause overflow? No. Mathematically, “fraction of available space” means that the second column will receive&lt;code&gt;(flex number * available space) / combined number of flex units&lt;/code&gt;. This means that if there’s 100 pixels of available space, the right column will be (2 * 100) / 2 pixels wide, so still 100 pixels. It’s like mixing drinks: no specific measurements, but rather “2 parts tequila, 1 part whisky, 1 part bitter tears” (That would probably be a horrible cocktail. Then again, I’m not a licensed mixologist).&lt;/p&gt;

&lt;p&gt;If we were to add another column also sized to &lt;code&gt;1fr&lt;/code&gt;, the middle and right columns would be equally wide – each is 1 fraction of the available space, i.e. 1/2.&lt;/p&gt;

&lt;pre class="code-block"&gt;&lt;code class="language-css"&gt;.grid-container {
  display: grid;
  grid-template-columns: 5em 1fr 1fr;
  grid-template-rows: auto auto;
}&lt;/code&gt;&lt;/pre&gt;

&lt;figure&gt;

&lt;p&gt;&lt;img src="/media/attachments/grid-1fr-1fr.png" alt="The three by two grid, where the second and third columns are equally wide. The second row is empty and invisible" /&gt;&lt;/p&gt;

&lt;figcaption markdown="-1"&gt;The B and C columns are now equally wide. Note that the second row in the grid is now empty, and collapses down to &lt;code&gt;0&lt;/code&gt; height. (&lt;a href="http://jsbin.com/naxaxe/12/edit?html,css,output"&gt;JSBin link for figure 3&lt;/a&gt;)&lt;/figcaption&gt;

&lt;/figure&gt;

&lt;p&gt;If we use different flexible lengths for the two tracks, we can see more clearly how the units relate to each other.&lt;/p&gt;

&lt;pre class="code-block"&gt;&lt;code class="language-css"&gt;.grid-container {
  display: grid;
  grid-template-columns: 5em 2fr 1fr;
  grid-template-rows: auto auto;
}&lt;/code&gt;&lt;/pre&gt;

&lt;figure&gt;

&lt;p&gt;&lt;img src="/media/attachments/grid-2fr-1f.png" alt="The three by two grid, where the second column is twice as wide as the third. The second row is empty and invisible" /&gt;&lt;/p&gt;

&lt;figcaption markdown="-1"&gt;The B column is now twice as wide as C. (&lt;a href="http://jsbin.com/naxaxe/14/edit?html,css,output"&gt;JSBin link for figure 4&lt;/a&gt;)&lt;/figcaption&gt;

&lt;/figure&gt;

&lt;p&gt;There’s three units competing for space in total (2fr + 1fr), so two thirds of the remaining space (&lt;em&gt;after&lt;/em&gt; the first column is sized) gets allocated to the second column, and one third to the second column.&lt;/p&gt;

&lt;h2&gt;Repeating grid tracks&lt;/h2&gt;

&lt;p&gt;If you’re dealing with a more complex grid than just a handful of columns, it get’s tedious to write out repeating columns of the same size. Luckily, the grid spec has this sorted: you can use the &lt;code&gt;repeat()&lt;/code&gt; functional notation. If we have a grid of 24 equal width columns (for example), you can just repeat a &lt;code&gt;1fr&lt;/code&gt; track 24 times.&lt;/p&gt;

&lt;pre class="code-block"&gt;&lt;code class="language-markup"&gt;&amp;lt;div class="grid-container"&amp;gt;
  &amp;lt;div class="grid-item-a"&amp;gt;A&amp;lt;/div&amp;gt;
  &amp;lt;div class="grid-item-b"&amp;gt;B&amp;lt;/div&amp;gt;
  &amp;lt;div class="grid-item-c"&amp;gt;C&amp;lt;/div&amp;gt;
  &amp;lt;div class="grid-item-a"&amp;gt;A&amp;lt;/div&amp;gt;
  &amp;lt;div class="grid-item-b"&amp;gt;B&amp;lt;/div&amp;gt;
  &amp;lt;div class="grid-item-c"&amp;gt;C&amp;lt;/div&amp;gt;
  &amp;lt;!-- ...and so on, 24 items --&amp;gt;
&amp;lt;/div&amp;gt;&lt;/code&gt;&lt;/pre&gt;

&lt;pre class="code-block"&gt;&lt;code class="language-css"&gt;.grid-container {
  display: grid;
  grid-template-columns: repeat(24, 1fr);
  grid-template-rows: auto auto;
}&lt;/code&gt;&lt;/pre&gt;

&lt;figure&gt;

&lt;p&gt;&lt;img src="/media/attachments/grid-24col.png" alt="The three by two grid, where the second column is twice as wide as the third. The second row is empty and invisible" /&gt;&lt;/p&gt;

&lt;figcaption markdown="-1"&gt;24 items in 24 equal width columns. (&lt;a href="http://jsbin.com/naxaxe/13/edit?html,css,output"&gt;JSBin link for figure 5&lt;/a&gt;)&lt;/figcaption&gt;

&lt;/figure&gt;

&lt;p&gt;You can mix and match repeated tracks with regularly declared tracks, in case some of them are different. If the first and last columns are of a different measurement, the track list for columns could look like this.&lt;/p&gt;

&lt;pre class="code-block"&gt;&lt;code class="language-css"&gt;.grid-container {
  display: grid;
  grid-template-columns: 5em repeat(22, 1fr) 5em;
  grid-template-rows: auto auto;
}&lt;/code&gt;&lt;/pre&gt;

&lt;h2&gt;Minimum and maximum sizes&lt;/h2&gt;

&lt;p&gt;Since we're sizing grid tracks rather than elements in the DOM, we can't use the &lt;code&gt;min-width&lt;/code&gt;, &lt;code&gt;max-width&lt;/code&gt;, &lt;code&gt;min-height&lt;/code&gt; and &lt;code&gt;max-height&lt;/code&gt; properties to size them. Instead, the Grid Layout spec introduces a functional notation for this purpose, appropriately called &lt;code&gt;minmax()&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;For instance, we might want the leftmost column to take up 20% of the width, but with a minimum width of &lt;code&gt;5em&lt;/code&gt;.&lt;/p&gt;

&lt;pre class="code-block"&gt;&lt;code class="language-css"&gt;.grid-container {
  display: grid;
  grid-template-columns: minmax(5em, 20%) 1fr 1fr;
  grid-template-rows: auto auto;
}&lt;/code&gt;&lt;/pre&gt;

&lt;aside class="entry-aside"&gt;

&lt;p&gt;It’s worth noting that you may use the &lt;code&gt;fr&lt;/code&gt; unit inside &lt;code&gt;minmax()&lt;/code&gt;, but it won’t do you much good unless it’s acting as the &lt;em&gt;maximum&lt;/em&gt; size. In effect, you can say “this track is at least &lt;code&gt;5em&lt;/code&gt;, but if there’s space enough it takes up this specified fraction of the available space”, but not the other way around.&lt;/p&gt;

&lt;p&gt;I’m not terribly confident with the reasoning, but I suspect this is because of the order in which the grid track sizing algorithm works. If you &lt;em&gt;do&lt;/em&gt; use an &lt;code&gt;fr&lt;/code&gt; unit as a minimum size, it will be treated as &lt;code&gt;0&lt;/code&gt; or &lt;code&gt;min-content&lt;/code&gt; (see next section on intrinsic sizing), depending on how the grid container is sized.&lt;/p&gt;

&lt;/aside&gt;

&lt;h2&gt;Intrinsic sizing keywords and auto sizing&lt;/h2&gt;

&lt;p&gt;So far, we have declared that the row tracks have an &lt;code&gt;auto&lt;/code&gt; height. What does that mean? Well, we’ve already concluded that it means that the track collapses down to &lt;code&gt;0&lt;/code&gt; height if the row is empty. If there are items placed in the row, it will expand to fit them. In simplified terms, this expand-to-fit behavior means that it will be as tall as the tallest grid item, depending on how the items themselves are sized.&lt;/p&gt;

&lt;p&gt;We can also use the keywords from the &lt;a href="http://www.w3.org/TR/css3-sizing/"&gt;Intrinsic &amp;amp; Extrinsic Sizing module&lt;/a&gt; to gain even more fine-grained control over how we size the tracks. If we’re dealing with a column containing some short text, we may want to size it so that it has a maximum size corresponding to the &lt;code&gt;max-content&lt;/code&gt; width.&lt;/p&gt;

&lt;pre class="code-block"&gt;&lt;code class="language-markup"&gt;&amp;lt;div class=";grid-container";&amp;gt;
  &amp;lt;div class="grid-item-a"&amp;gt;Hello world&amp;lt;/div&amp;gt;
  &amp;lt;div class="grid-item-b"&amp;gt;B&amp;lt;/div&amp;gt;
  &amp;lt;div class="grid-item-c"&amp;gt;C&amp;lt;/div&amp;gt;
&amp;lt;/div&amp;gt;&lt;/code&gt;&lt;/pre&gt;

&lt;pre class="code-block"&gt;&lt;code class="language-css"&gt;.grid-container {
  background-color: #E6CAD6;
  display: grid;
  grid-template-columns: minmax(5em, max-content) 1fr 1fr;
  grid-template-rows: auto auto;
}&lt;/code&gt;&lt;/pre&gt;

&lt;figure&gt;

&lt;p&gt;&lt;img src="/media/attachments/max-content.png" alt="A three column grid, where the first column contains the words ”hello world.”" /&gt;&lt;/p&gt;

&lt;figcaption markdown="-1"&gt;As long as there’s any space left, the first column will now expand to fit the words “Hello world. (&lt;a href="http://jsbin.com/tisipu/2/edit?html,css,output"&gt;JSBin link for figure 6&lt;/a&gt;)&lt;/figcaption&gt;

&lt;/figure&gt;

&lt;p&gt;If we add a fourth item to the grid, it will end up on row two (via the rules of auto placement – don’t worry, we’ll get back to that in later tidbits). If the content inside that item is even wider, then the whole track will have a larger min-content size. So: &lt;code&gt;max-content&lt;/code&gt; means “the largest max-content item inside the track”.&lt;/p&gt;

&lt;pre class="code-block"&gt;&lt;code class="language-markup"&gt;&amp;lt;div class="grid-container"&amp;gt;
  &amp;lt;div class="grid-item-a"&amp;gt;Hello world!&amp;lt;/div&amp;gt;
  &amp;lt;div class="grid-item-b"&amp;gt;B&amp;lt;/div&amp;gt;
  &amp;lt;div class="grid-item-c"&amp;gt;C&amp;lt;/div&amp;gt;
  &amp;lt;div class="grid-item-d"&amp;gt;Hello big world!&amp;lt;/div&amp;gt;
&amp;lt;/div&amp;gt;&lt;/code&gt;&lt;/pre&gt;

&lt;pre class="code-block"&gt;&lt;code class="language-css"&gt;.grid-item-d {
  background-color: #274461;
}&lt;/code&gt;&lt;/pre&gt;

&lt;figure&gt;

&lt;p&gt;&lt;img src="/media/attachments/max-content-2.png" alt="A three column grid, where the first column contains the words ”hello world.”" /&gt;&lt;/p&gt;

&lt;figcaption markdown="-1"&gt;The “D” item pushes on the max-content size of the first column (&lt;a href="http://jsbin.com/tisipu/6/edit?html,css,output"&gt;JSBin link for figure 7&lt;/a&gt;)&lt;/figcaption&gt;

&lt;/figure&gt;

&lt;p&gt;To me personally, track sizing in the grid layout module is one of the places where I’ve actually seen immediate use for the intrinsic sizing keywords in CSS. (On the other hand, I suspect that they're highly useful elsewhere, but I haven’t worked them into my thinking yet.) These keywords have been around for a while, but support is still spotty, with mostly prefixed implementations.&lt;/p&gt;

&lt;h2&gt;Wrap-up&lt;/h2&gt;

&lt;p&gt;That’s it for the first pass of sizing grid tracks! There’s more to come – we haven’t even gotten started on gutters, named lines or template areas yet… These first posts have been slightly longer than anticipated, but as we get to grips with the basics, we can discuss other concepts in shorter form ahead. So stay tuned for more tidbitty tidbits!&lt;/p&gt;

&lt;p&gt;The tidbits so far:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;a href="/blog/2015/06/30/grid-tidbits-1-why-where/"&gt;The why and where of Grid Layout&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="/blog/2015/07/12/grid-tidbits-2-terminology-basics/"&gt;Terminology and basics&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Grid track sizing (this part)&lt;/li&gt;
&lt;/ol&gt;

</description><guid>https://thatemil.com/blog/2015/08/24/grid-tidbits-3-track-sizing/</guid></item><item><title>Grid Tidbits part 2: terminology and basics</title><link>https://thatemil.com/blog/2015/07/12/grid-tidbits-2-terminology-basics/</link><description>


&lt;div style="font-weight:700"&gt;

&lt;p&gt;This post goes through the terminology of CSS Grid Layout, the basics of defining grid templates, and placing items on the grid.&lt;/p&gt;

&lt;/div&gt;

&lt;aside class="entry-aside"&gt;

&lt;p&gt;This is the second post in a series of reasonably short pieces on Grid Layout. &lt;a href="/blog/2015/06/30/grid-tidbits-1-why-where/"&gt;Part One&lt;/a&gt; goes over the “why” of grids, and the current browser situation.&lt;/p&gt;

&lt;/aside&gt;

&lt;p&gt;For this ”tidbit”, we're going to do the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Take an element and convert it to a grid.&lt;/li&gt;
&lt;li&gt;Watch items place themselves onto the grid&lt;/li&gt;
&lt;li&gt;Start playing with how to control the placement.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To play along with the examples in this post, I recommend that you download and fire up &lt;a href="https://www.google.se/chrome/browser/canary.html"&gt;Google Chrome Canary&lt;/a&gt;, since that browser has the most up-to-date implementation.&lt;/p&gt;

&lt;h2&gt;Grid terminology&lt;/h2&gt;

&lt;p&gt;Grid layout works by ”slicing” an element – called a &lt;em&gt;grid container –&lt;/em&gt; into  rows and columns. The direct child  elements of the container element – the &lt;em&gt;grid items&lt;/em&gt; – can then be placed on that grid. Grid items can occupy a single &lt;em&gt;grid cell&lt;/em&gt;, or span several rows or columns. Collectively, any rectangular part of the grid is known as a &lt;em&gt;grid area&lt;/em&gt;. As you are creating rows and columns – known collectively as &lt;em&gt;grid tracks&lt;/em&gt; – you are also creating &lt;em&gt;grid lines&lt;/em&gt;, made up by the edges of the tracks.&lt;/p&gt;

&lt;p&gt;We'll start by creating a simple grid and then identify these pieces as we go along. The markup for now is just a container &lt;code&gt;div&lt;/code&gt; and three child elements.&lt;/p&gt;

&lt;pre class="code-block"&gt;&lt;code class="language-markup"&gt;&amp;lt;div class=&amp;quot;grid-container&amp;quot;&amp;gt;
  &amp;lt;div class=&amp;quot;grid-item-a&amp;quot;&amp;gt;A&amp;lt;/div&amp;gt;
  &amp;lt;div class=&amp;quot;grid-item-b&amp;quot;&amp;gt;B&amp;lt;/div&amp;gt;
  &amp;lt;div class=&amp;quot;grid-item-c&amp;quot;&amp;gt;C&amp;lt;/div&amp;gt;
&amp;lt;/div&amp;gt;&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Some basic styling to give some dimensions and identify the different pieces with colors:&lt;/p&gt;

&lt;pre class="code-block"&gt;&lt;code class="language-css"&gt;.grid-container {
  background-color: #E6CAD6;
}
[class^="grid-item"] {
  border: 1px solid #fff;
  font-size: 4em;
  min-height: 2.5em;
  line-height: 2.5em;
  text-align: center;
  color: #fff;
}
.grid-item-a {
  background-color: #3D74C7;
}
.grid-item-b {
  background-color: #85CAAA;
}
.grid-item-c {
  background-color: #DAB97D;
}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Now, what happens if we tell the &lt;code&gt;.grid-container&lt;/code&gt; element to display as a &lt;code&gt;grid&lt;/code&gt;, and just leave it at that?&lt;/p&gt;

&lt;pre class="code-block"&gt;&lt;code class="language-css"&gt;.grid-container {
  display: grid;
}&lt;/code&gt;&lt;/pre&gt;

&lt;figure&gt;

&lt;p&gt;&lt;img src="/media/attachments/grid-notemplate.png" alt="A grid container, with the items shrunken down in a column to the left." /&gt;&lt;/p&gt;

&lt;figcaption markdown="-1"&gt;The bare grid container. (&lt;a href="http://jsbin.com/vayaqa/1/edit?html,css,output"&gt;JSBin link for figure 1&lt;/a&gt;)&lt;/figcaption&gt;

&lt;/figure&gt;

&lt;p&gt;The only thing that seems to happen from a visual point of view is that the width of the four items shrinks down to the content-size of the items themselves. But we &lt;em&gt;have&lt;/em&gt; actually created a grid, where there's one column and three rows, all of them sized according to content. This is because of something called the &lt;em&gt;implicit grid&lt;/em&gt; – we'll talk more about that in later posts.&lt;/p&gt;

&lt;aside class="entry-aside"&gt;

&lt;p&gt;Note that there's also a display keyword called &lt;code&gt;inline-grid&lt;/code&gt; – just like &lt;code&gt;inline-block&lt;/code&gt; or &lt;code&gt;inline-flex&lt;/code&gt;. Does what it says on the tin: works like a grid block, but sits in the inline flow.&lt;/p&gt;

&lt;/aside&gt;

&lt;h2&gt;The grid template&lt;/h2&gt;

&lt;p&gt;To get further, we need to define how the grid works. Say we wanted two columns of 50% percent each, and two rows that have an &lt;code&gt;auto&lt;/code&gt; height, meaning they are only as tall as the tallest content. For this next trick, we need need the assistance of a grid template. The grid template defines the tracks (columns and rows), and in their simplest form we supply them as space separated lists of sizes, in order of appearance.&lt;/p&gt;

&lt;aside class="entry-aside"&gt;

&lt;p&gt;Note that these sizes define the tracks in the text-order, so for left-to-right languages the first column is the one farthest to the left, but this is changes with the text-direction.&lt;/p&gt;

&lt;/aside&gt;

&lt;pre class="code-block"&gt;&lt;code class="language-css"&gt;.grid-container {
  display: grid;
  grid-template-columns: 50% 50%;
  grid-template-rows: auto auto;
}&lt;/code&gt;&lt;/pre&gt;

&lt;figure&gt;

&lt;p&gt;&lt;img src="/media/attachments/grid-auto.png" alt="Grid with four cells in rows of two, where the three items take up three of the cells." /&gt;&lt;/p&gt;

&lt;figcaption&gt;Hey look, it’s properly grid-shaped!. (&lt;a href="http://jsbin.com/vayaqa/2/edit?html,css,output"&gt;JSbin link for figure 2&lt;/a&gt;)&lt;/figcaption&gt;

&lt;/figure&gt;

&lt;p&gt;Well, hey now. That is an honest to goodness grid-shaped thingamajig. Our grid items fit neatly into three of the four cells we have defined, and the grid takes up the whole width. Nice. But – we didn't actually place anything yet, and still the items line up column by column, row by row – what's up with that? Well, the grid layout has something called &lt;em&gt;automatic placement&lt;/em&gt; and by default it will place each item, going by source order, in the first empty cell of the first row which has an empty cell. So our three child elements will automatically go into three of the empty cells, all by themselves. Neat.&lt;/p&gt;

&lt;h2&gt;Numbered grid lines&lt;/h2&gt;

&lt;p&gt;As we created two grid tracks in each dimension, we also created three grid lines in each dimension. For two columns, there's the leftmost line, the middle line and the rightmost line. Similarly, there's  top, middle and bottom for rows. These can now be referenced by a number. Grid lines are numbered starting at &lt;code&gt;1&lt;/code&gt; . (No, not &lt;code&gt;0&lt;/code&gt;. You've been reading too much JavaScript, friend.)&lt;/p&gt;

&lt;p&gt;For our left-to-right grid, line 1 is the leftmost column line, and line 3 is the last.&lt;/p&gt;

&lt;figure&gt;

&lt;p&gt;&lt;img src="/media/attachments/grid-lines.png" alt="Illustration of the numbered grid lines." /&gt;&lt;/p&gt;

&lt;figcaption&gt;The numbers of grid lines. I see them as almost like the ruler lines in Illustrator, Photoshop or Sketch etc.&lt;/figcaption&gt;

&lt;/figure&gt;

&lt;h2&gt;Placing items&lt;/h2&gt;

&lt;p&gt;Now for some real meaty stuff: telling items to take up a specific part of the grid. We could, for example, have the &lt;code&gt;.grid-item-a&lt;/code&gt; element take up both of the columns in the first row. To do this, we need to supply the lines where it starts and ends.&lt;/p&gt;

&lt;pre class="code-block"&gt;&lt;code class="language-css"&gt;.grid-item-a {
  grid-row-start: 1;
  grid-row-end: 2;
  grid-column-start: 1;
  grid-column-end: 3;
}&lt;/code&gt;&lt;/pre&gt;

&lt;figure&gt;

&lt;p&gt;&lt;img src="/media/attachments/grid-span.png" alt="Grid with four cells in rows of two, where the first item takes up the whole first row." /&gt;&lt;/p&gt;

&lt;figcaption&gt;Item A now spans the whole first row. (&lt;a href="http://jsbin.com/vayaqa/3/edit?html,css,output"&gt;JSbin link for figure 3&lt;/a&gt;)&lt;/figcaption&gt;

&lt;/figure&gt;

&lt;p&gt;Now, this is a bit verbose. We can use a shorter version by smashing the &lt;code&gt;-start&lt;/code&gt; and &lt;code&gt;-end&lt;/code&gt; properties together into the &lt;code&gt;grid-row&lt;/code&gt; and &lt;code&gt;grid-column&lt;/code&gt; properties, &lt;a href="http://jsbin.com/vayaqa/edit?css,output"&gt;separating the start and end indexes by a slash&lt;/a&gt;:&lt;/p&gt;

&lt;pre class="code-block"&gt;&lt;code class="language-css"&gt;.grid-item-a {
  grid-row: 1/2;
  grid-column: 1/3;
}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Well, screw it, let's go for it and smash them into something even shorter. Since what we're actually doing is defining the grid area where the item sits, there is a &lt;a href="http://jsbin.com/vayaqa/11/edit?css,output"&gt;full shorthand property&lt;/a&gt; conveniently named &lt;code&gt;grid-area&lt;/code&gt;.&lt;/p&gt;

&lt;pre class="code-block"&gt;&lt;code class="language-css"&gt;.grid-item-a {
  grid-area: 1/1/2/3;
}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;I don't know about you, but I find that kind of hard to read. The order is &lt;code&gt;row-start&lt;/code&gt; /&lt;code&gt;column-start&lt;/code&gt; / &lt;code&gt;row-end&lt;/code&gt; / &lt;code&gt;column-end&lt;/code&gt; – so compared to margin or padding shorthands, it's going the opposite way. &lt;em&gt;(As a sidenote, the reason is that it allows you to omit end positions  for items that only span one cell)&lt;/em&gt;.&lt;/p&gt;

&lt;h2&gt;Negative line numbers and spans&lt;/h2&gt;

&lt;p&gt;By default, items span one row and one column. As we've already seen, items are automatically placed into the first empty area where they fit, via the automatic placement algorithm. As the &lt;code&gt;.grid-item-a&lt;/code&gt; element is first in the source order, we don't really have to specify either of these facts:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;That it sits in the first row&lt;/li&gt;
&lt;li&gt;That it spans one row&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Hold that thought for a second.&lt;/p&gt;

&lt;p&gt;If we want to reference the grid lines in the opposite direction, we can use negative numbers: the rightmost column line is &lt;code&gt;-1&lt;/code&gt;, and the leftmost is &lt;code&gt;-3&lt;/code&gt;.
We might have a situation where we are not sure how many columns the final grid will have, but we are sure that &lt;code&gt;.grid-item-a&lt;/code&gt; should span all the columns. In that case, the negative line numbering is really handy.&lt;/p&gt;

&lt;p&gt;Combining the default placement with the negative indexing gives us a really short way to define the item &lt;a href="http://jsbin.com/vayaqa/12/edit?html,css,output"&gt;spanning the whole of the first row&lt;/a&gt;.&lt;/p&gt;

&lt;pre class="code-block"&gt;&lt;code class="language-css"&gt;.grid-item-a {
  grid-column: 1/-1;
}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;If we're not interested in spanning the whole row, but more interested in the fact that the element spans a specific number of columns, we can be explicit about that fact instead. Since the starting position is already set by auto placement (first element in source order, starts in column 1, row 1) , we can fall back to only &lt;a href="http://jsbin.com/vayaqa/14/edit?html,css,output"&gt;specifying that &amp;lt;code&amp;gt;.grid-item-a&amp;lt;/code&amp;gt; spans two columns&lt;/a&gt;.&lt;/p&gt;

&lt;pre class="code-block"&gt;&lt;code class="language-css"&gt;.grid-item-a {
  grid-column: span 2;
}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;All of these ways of specifying placement of this particular grid item gives us the same result, but with different levels of readability, and different levels of explicitly placing and sizing the item.&lt;/p&gt;

&lt;h2&gt;Spanning rows &amp;amp; column height&lt;/h2&gt;

&lt;p&gt;If we switch the “a”-item to span two rows instead of two columns, we can place it as a sidebar of sorts, and the other two items will fill the other two empty slots.&lt;/p&gt;

&lt;pre class="code-block"&gt;&lt;code class="language-css"&gt;.grid-item-a {
  grid-row: 1/-1;
}&lt;/code&gt;&lt;/pre&gt;

&lt;figure&gt;

&lt;p&gt;&lt;img src="/media/attachments/grid-rowspan.png" alt="Grid with four cells in rows of two, where the first item takes up the whole left column." /&gt;&lt;/p&gt;

&lt;figcaption&gt;Item A now spans the whole first column instead. (&lt;a href="http://jsbin.com/vayaqa/15/edit?html,css,output"&gt;JSBin link for figure 4&lt;/a&gt;)&lt;/figcaption&gt;

&lt;/figure&gt;

&lt;p&gt;Now, if the “C”-item were to be much taller, the “A”-item would still stretch to take up all of the height of the grid. No more “equal height columns” problems.&lt;/p&gt;

&lt;pre class="code-block"&gt;&lt;code class="language-css"&gt;.grid-item-c {
  height: 6em;
}&lt;/code&gt;&lt;/pre&gt;

&lt;figure&gt;

&lt;p&gt;&lt;img src="/media/attachments/grid-autoheight.png" alt="Grid with four cells in rows of two, where the second row is much taller because of taller content in the bottom right cell." /&gt;&lt;/p&gt;

&lt;figcaption&gt;Item C pushes the height of the entire second row. (&lt;a href="http://jsbin.com/vayaqa/19/edit?html,css,output"&gt;JSBin link for figure 5&lt;/a&gt;)&lt;/figcaption&gt;

&lt;/figure&gt;

&lt;p&gt;That's all you need to create a basic grid container and placing things inside the grid tracks – rows and columns – you create. In the next installment, we are going to dive into some more advanced parts of defining grids. See you in &lt;a href="/blog/2015/08/24/grid-tidbits-3-track-sizing/"&gt;part three&lt;/a&gt;, where we get deep into sizing grid tracks!&lt;/p&gt;

</description><guid>https://thatemil.com/blog/2015/07/12/grid-tidbits-2-terminology-basics/</guid></item><item><title>Grid tidbits, part 1: the Why and Where</title><link>https://thatemil.com/blog/2015/06/30/grid-tidbits-1-why-where/</link><description>


&lt;div style="font-weight:700"&gt;

&lt;p&gt;&lt;a href="http://www.w3.org/TR/css-grid-1/"&gt;CSS Grid Layout&lt;/a&gt; is a new way of handling layout in browsers. It differs from other methods (like flexbox) in perspective and capabilities, but it also overlaps somewhat. Oh, and it's going to be in a lot of browsers real soon. This post gives you an overview of what it is, and what it's for.&lt;/p&gt;

&lt;/div&gt;

&lt;aside class="entry-aside"&gt;

&lt;p&gt;This is the first post in a series of reasonably short pieces on Grid Layout. Rather than give you the ”everything you need to know about Grid Layout” post (which would never be written, because I'm lazy), I thought I'd try to break it down into easy-to-digest pieces. Now, it's a pretty massive spec, so ”reasonably short” is very relative.&lt;/p&gt;

&lt;p&gt;The posts will assume at least some basic knowledge of CSS layout including Flexbox.&lt;/p&gt;

&lt;/aside&gt;

&lt;p&gt;So. You might be going ”oh great, yet another new layout mechanism in CSS, and I was &lt;em&gt;just&lt;/em&gt; starting to get to grips with Flexbox”. In that case, this post (and the rest of the series) is for you.&lt;/p&gt;

&lt;p&gt;This post is not about code. Just to give you a taste of both some basics and some more advanced features, here's what (a small part) of the Grid syntax looks like:&lt;/p&gt;

&lt;pre&gt;&lt;code class="language-css"&gt;/**
* Assume this markup:
* &amp;lt;div class="grid-container"&amp;gt;
*   &amp;lt;div class="grid-item"&gt;&amp;lt;/div&amp;gt;
* &amp;lt;/div&amp;gt;
*/

/**
* A grid container element with one row
* of automatic content height
* and five columns, where the first
* is at least 12em wide and otherwise
* 25%, and the remaining four are of
* equal width in the space that's left.
*/
.grid-container {
  display: grid;
  grid-template-rows: auto;
  grid-template-columns: minmax(12em, 25%) repeat(4, 1fr);
}

/**
* A child element inside the container
* placed in row 1, starting at column 2
* and spanning 2 columns.
*/
.grid-item {
  grid-row: 1;
  grid-column: 2/span 2;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;At first glance, this might look sort-of-kinda like Flexbox. You set a display mode and some general layout rules on the parent, and some details on a child element. There's even some flexible units dealing with remaining space. Let's stay in flexbox-land for a second.&lt;/p&gt;

&lt;p&gt;Flexbox is great. It gives us the possibility to size stuff in a number of different ways, and have it line up neatly in one or more rows, or columns. Yay for non-hacky horizontal layout! It also offers freedom from markup source order, and lets you align and distribute content more easily. From one perspective, the core strength of flexbox is to &lt;em&gt;let content size itself&lt;/em&gt; based on things like available space, or the content dimensions. This is the first big conceptual difference between Flexbox and Grid.&lt;/p&gt;

&lt;h2&gt;Grid is top-down&lt;/h2&gt;

&lt;p&gt;Looking at the code example above, there is at least one major difference from how flexbox works. There is nothing in the rule-set for the &lt;em&gt;item&lt;/em&gt; saying how it is to be sized. All the sizing takes place in the grid container. You make an element into a grid container, slice it into rows and columns at specific points along the two axes, and then place the child elements into the slots that are created.&lt;/p&gt;

&lt;p&gt;Where Flexbox has a lot of focus on how to size the item itself, grid is more about creating a bunch of virtual receptacles and pouring your content into them. This doesn't mean that Grid is inflexible – as you can see from the code example, there's plenty of flexibility. You are free to size the columns and rows (known collectively as &lt;em&gt;grid tracks&lt;/em&gt;) based on content size, remaining space, percentages etc etc.&lt;/p&gt;

&lt;p&gt;This means that Grid is great for more high-level layout. You can use it to define the overall layout system of whole pages, but more likely, you'll use Grid to define the layout of larger sections of a page. We'll get more into the use-cases in later installments.&lt;/p&gt;

&lt;h2&gt;Grid is two-dimensional&lt;/h2&gt;

&lt;p&gt;When you're creating layouts with floats, table display modes, inline-blocks or Flexbox you can create horizontal rows – columns lining up from left-to-right or right-to-left. Some of these allow you to create wrapping rows. But as soon as you want to have one item spanning multiple rows, you'll need to further divide things with wrapper elements. For complex layouts, that can mean a lot of wrapper elements.&lt;/p&gt;

&lt;p&gt;All of these methods are in a sense &lt;em&gt;one-dimesional&lt;/em&gt;: you can create rows or columns, but not in any sense that make the two aware of each other. Grids are two-dimensional: you can create layouts as complex as you like. If you want a great illustration of the differences, check out this &lt;a href="https://vimeo.com/98746172"&gt;talk by Tab Atkins from CSSDay 2014&lt;/a&gt;. Meanwhile, check figure 1 – how many wrappers would you need to recreate that with floats or Flexbox? Grids make this easy-peasy.&lt;/p&gt;

&lt;figure&gt;

&lt;p&gt;&lt;img src="/media/attachments/grid-2d.png" alt="A complex 2D-grid." /&gt;&lt;/p&gt;

&lt;figcaption&gt;A complex 2D-grid.&lt;/figcaption&gt;

&lt;/figure&gt;

&lt;h2&gt;Grid is coming soon&lt;/h2&gt;

&lt;p&gt;So, at this point, you may be going ”OK, maybe there is good reason for this new Grid thing. But it's not supported anywhere, almost!”. Well, yes, and no. Here’s the lowdown.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;All the major browser makers are on board with this spec.&lt;/li&gt;
&lt;li&gt;It is expected that the spec will be finalized this summer.&lt;/li&gt;
&lt;li&gt;Grid Layout is already supported in IE10+, but it's a slightly older version of the spec. It can still do the basics, but it's missing a lot of the new shiny. It's &lt;code&gt;-ms-&lt;/code&gt;-prefixed though, so you have to tweak the syntax slightly.&lt;/li&gt;
&lt;li&gt;Blink and WebKit are both very far along with their implementation, you can try it out in Chrome Canary or WebKit Nightly. The same &lt;a href="http://blogs.igalia.com/mrego/tag/css-grid-layout/"&gt;people are implementing it in both engines&lt;/a&gt;, so they're pretty in-sync.&lt;/li&gt;
&lt;li&gt;Firefox is not far behind, and things are happening if you &lt;a href="https://bugzilla.mozilla.org/show_bug.cgi?id=616605"&gt;look in Bugzilla&lt;/a&gt;. &lt;strong&gt;Note:&lt;/strong&gt; I think that the later stuff is not yet merged with the trunk codebase, so the nightlies only have a very buggy version hidden behind a flag inside &lt;code&gt;about:config&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It seems very likely that Grid will land in all of the major browsers within a year, if I'm being conservative. IE is in a slight pickle, as they already have the old version with prefixes, so they'll probably hold off shipping the unprefixed modern spec in Edge a little while. I’d say it's a pretty safe bet that they are working to get it out ASAP. Safari is stuck in the stone age with their once-a-year release cycles, but hey, at least it' being worked on very actively in WebKit. If there isn't a change in policy and a point release contains Grid, it'll probably be in Safari iOS/Mac next year.&lt;/p&gt;

&lt;p&gt;To sum up, there's a massive new layout technology that will be in a large percentage of browsers within a year. If you want to be ready, read on in &lt;a href="/blog/2015/07/12/grid-tidbits-2-terminology-basics/"&gt;part two&lt;/a&gt;!.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;This article has been &lt;a href="http://css-live.ru/articles/lakomye-kusochki-grid-rasklaki-chast-1-zachem-i-pochemu.html"&gt;translated to Russian at css-live.ru&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description><guid>https://thatemil.com/blog/2015/06/30/grid-tidbits-1-why-where/</guid></item></channel></rss>