<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Dominic Whittle on Medium]]></title>
        <description><![CDATA[Stories by Dominic Whittle on Medium]]></description>
        <link>https://medium.com/@DominicWhittle?source=rss-19bf26ec9522------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*P3YGwqXTcIf0UO2x.png</url>
            <title>Stories by Dominic Whittle on Medium</title>
            <link>https://medium.com/@DominicWhittle?source=rss-19bf26ec9522------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 02:59:32 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@DominicWhittle/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[BEM + Context]]></title>
            <link>https://medium.com/@DominicWhittle/bem-context-5edcef8e539d?source=rss-19bf26ec9522------2</link>
            <guid isPermaLink="false">https://medium.com/p/5edcef8e539d</guid>
            <dc:creator><![CDATA[Dominic Whittle]]></dc:creator>
            <pubDate>Fri, 06 Mar 2015 01:59:24 GMT</pubDate>
            <atom:updated>2015-03-06T01:59:34.755Z</atom:updated>
            <content:encoded><![CDATA[<p>BEM — <strong>B</strong>lock <strong>E</strong>lement <strong>M</strong>odifier — is a powerful convention for maintaining legibility and meaning in CSS class names. I won’t go into the details here but have put some links in the footer for background reading. Instead I’d like to introduce something I’ve been experimenting with on a few projects: the <strong>Context</strong> convention.</p><h4>The Problem</h4><p>Philip Walton published an article a couple of days ago on how the BEM methodology helps prevent some of the <a href="http://philipwalton.com/articles/side-effects-in-css/#side-effects-in-css">side effects</a> that come from the cascading nature of CSS. Read the whole thing, it’s a good article.</p><p>As with most articles about BEM, there’s a little disclaimer; <a href="http://philipwalton.com/articles/side-effects-in-css/#making-exceptions">making exceptions</a>.</p><p>To summarise a little, in BEM this kind of thing is frowned upon:</p><pre>// Don&#39;t do this<br>.sidebar .block {<br>  // Styles to make this Block different when placed in the sidebar<br>}</pre><p>But… we do sometimes want change our blocks’ styling based on their context:</p><pre>// Using feature detection with Modernizr<br>.no-flexbox .block {<br>  // Fallback layout styles <br>  // Pretty important that we can do this<br>}</pre><h4>Introducing the Context Convention</h4><p>The convention is simple. All classes that arbitrarily style other blocks (and elements) have an asterisk appended to the class name. (The asterisk feels appropriate to me because it hints at the universal selector.)</p><blockquote>classname*</blockquote><p>In your stylesheets this means escaping the <strong>*</strong> with a backslash, but you can drop a classname containing an asterisk straight in to your markup as is. I typically use contexts with BEM in a couple of ways:</p><p>1 — When you have stylistically different sections of the site; e.g., perhaps you add a context class of <strong>night*</strong> to areas that have dark backgrounds. Your styling for blocks you make compatible for use in that context might look something like:</p><pre>.night\* .block {<br>  color: white;<br>  // overriding block styling based on use within a context<br>}</pre><p>2 — When a specific areas of the site call for overrides of straight-up base elements.</p><pre>.article\* h1 { ... }<br>.article\* p  { ... }<br>.article\* ul { ... }<br>// and so on</pre><p>The idea is not to fix the problem of specificity, but to have a syntax that makes these exceptions to the BEM rules more legible and meaningful.</p><p>This isn’t exactly an exhaustive article on the idea, but hopefully you get the idea.</p><p>Let me know if it works for you.</p><p><a href="http://csswizardry.com/2013/01/mindbemding-getting-your-head-round-bem-syntax/">Getting Your Head ’Round BEM Syntax</a> is a nice introduction by Harry Roberts. For a detailed take on why approaches like BEM matter, check out Nicolas Gallagher’s <a href="http://nicolasgallagher.com/about-html-semantics-front-end-architecture/">About HTML Semantics and Front-end Architecture</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5edcef8e539d" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>