{"id":4229,"date":"2017-03-02T00:00:07","date_gmt":"2017-03-01T23:00:07","guid":{"rendered":"https:\/\/undsgn.com\/uncode\/?p=4229"},"modified":"2017-03-02T00:00:07","modified_gmt":"2017-03-01T23:00:07","slug":"time-is-passing-by","status":"publish","type":"post","link":"https:\/\/wordley.com.au\/time-is-passing-by\/","title":{"rendered":"Time is passing by"},"content":{"rendered":"

CSS selectors all exist within the same global scope.\u00a0Anyone who has worked with CSS long enough has had to come to terms with its aggressively global nature\u200a\u2014\u200aa model clearly designed in the age of documents, now struggling to offer a sane working environment for today\u2019s modern web applications.\u00a0Every selector has the potential to have unintended side effects by targeting unwanted elements or clashing with other selectors. More surprisingly, our selectors may even lose out in the global specificity war, ultimately having little or no effect on the page at all.<\/p>\n

Any time we make a change to a CSS file, we need to carefully consider the global environment in which our styles will sit. No other front end technology requires so much discipline just to keep the code at a minimum level of maintainability.\u00a0But it doesn\u2019t have to be this way.\u00a0It\u2019s time to leave the era of global style sheets behind.<\/p>\n

It\u2019s time for local CSS.<\/em><\/p>\n

In other languages, it\u2019s accepted that modifying the global environment<\/strong> is something to be done rarely, if ever.<\/p><\/blockquote>\n

In the JavaScript community, thanks to tools like Browserify, Webpack and JSPM, it\u2019s now expected that our code will consist of small modules, each encapsulating their explicit dependencies, exporting a minimal API.<\/p>\n

Yet, somehow, CSS still seems to be getting a free pass.<\/p>\n

Many of us\u200a\u2014\u200amyself included, until recently\u200a\u2014\u200ahave been working with CSS so long that we don\u2019t see the lack of local scope as a problem that we can solve without significant help from browser vendors. Even then, we\u2019d still need to wait for the majority of our users to be using a browser with proper Shadow DOM support.<\/p>\n

We\u2019ve worked around the issues of global scope with a series of naming conventions like OOCSS<\/strong>, SMACSS<\/strong>, BEM<\/strong> and SUIT<\/strong>, each providing a way for us to avoid naming collisions and emulate sane scoping rules.<\/p>\n

We no longer need to add lengthy prefixes to all of our selectors to simulate scoping. More components could define their own foo and bar identifiers which\u200a\u2014\u200aunlike the traditional global selector model\u2014wouldn\u2019t produce any naming collisions.<\/p>\n

import<\/strong> styles from<\/strong> '.\/MyComponent.css';\nimport<\/strong> React, { Component } from<\/strong> 'react';\nexport default class<\/strong> MyComponent extends<\/strong> Component {\n render<\/strong>() {\n    return (\n      <div>\n        <div className={styles.foo<\/strong>}>Foo<\/strong><\/div>\n        <div className={styles.bar<\/strong>}>Bar<\/strong><\/div>\n      <\/div>\n    );\n  }<\/pre>\n

The benefits of global CSS\u200a\u2014\u200astyle re-use between components via utility classes, etc.\u200a\u2014\u200aare still achievable with this model. The key difference is that, just like when we work in other technologies, we need to explicitly import the classes that we depend on. Our code can\u2019t make many, if any, assumptions about the global environment.<\/p>\n

Writing maintainable CSS is now encouraged, not by careful adherence to a naming convention<\/strong>, but by style encapsulation during development.<\/p><\/blockquote>\n

Once you\u2019ve tried working with local CSS, there\u2019s really no going back. Experiencing true local scope in our style sheets\u200a\u2014\u200ain a way that works across all browsers\u2014 is not something to be easily ignored.<\/p>\n

Introducing local scope has had a significant ripple effect on how we approach our CSS. Naming conventions, patterns of re-use, and the potential extraction of styles into separate packages are all directly affected by this shift, and we\u2019re only at the beginning of this new era of local CSS.<\/p>\n

process.env.NODE_ENV === 'development' ?\n    '[name]__[local]___[hash:base64:5]<\/strong>' :\n    '[hash:base64:5]'\n<\/strong>)<\/pre>\n

Understanding the ramifications of this shift is something that we\u2019re still working through. With your valuable input and experimentation, I\u2019m hoping that this is a conversation we can have together as a larger community.<\/p>\n

Note: Automatically optimising style re-use between components would be an amazing step forward, but it definitely requires help from people a lot smarter than me. <\/em><\/p>\n","protected":false},"excerpt":{"rendered":"

Every selector has the potential to have unintended side effects by targeting unwanted elements or clashing with other selectors. More surprisingly, our selectors may even lose out in the global specificity war, ultimately having little or no effect on the page at all. Any time we make a change to a CSS file, we need to carefully consider the global environment in which our styles will sit. No other front end technology requires so much discipline just to keep the code at a minimum level of maintainability.<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":"","_links_to":"","_links_to_target":""},"categories":[20],"tags":[22,25,27,30],"class_list":["post-4229","post","type-post","status-publish","format-standard","hentry","category-business","tag-travel","tag-tech","tag-life","tag-sport"],"yoast_head":"\nTime is passing by - Milton Wordley Photographer<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/wordley.com.au\/time-is-passing-by\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Time is passing by - Milton Wordley Photographer\" \/>\n<meta property=\"og:description\" content=\"Every selector has the potential to have unintended side effects by targeting unwanted elements or clashing with other selectors. More surprisingly, our selectors may even lose out in the global specificity war, ultimately having little or no effect on the page at all. Any time we make a change to a CSS file, we need to carefully consider the global environment in which our styles will sit. No other front end technology requires so much discipline just to keep the code at a minimum level of maintainability.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/wordley.com.au\/time-is-passing-by\/\" \/>\n<meta property=\"og:site_name\" content=\"Milton Wordley Photographer\" \/>\n<meta property=\"article:published_time\" content=\"2017-03-01T23:00:07+00:00\" \/>\n<meta name=\"author\" content=\"Duografik\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Duografik\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/wordley.com.au\/time-is-passing-by\/\",\"url\":\"https:\/\/wordley.com.au\/time-is-passing-by\/\",\"name\":\"Time is passing by - Milton Wordley Photographer\",\"isPartOf\":{\"@id\":\"https:\/\/wordley.com.au\/#website\"},\"datePublished\":\"2017-03-01T23:00:07+00:00\",\"dateModified\":\"2017-03-01T23:00:07+00:00\",\"author\":{\"@id\":\"https:\/\/wordley.com.au\/#\/schema\/person\/e44f8fe828213224317d61638368d1b3\"},\"breadcrumb\":{\"@id\":\"https:\/\/wordley.com.au\/time-is-passing-by\/#breadcrumb\"},\"inLanguage\":\"en-AU\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/wordley.com.au\/time-is-passing-by\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/wordley.com.au\/time-is-passing-by\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/wordley.com.au\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Time is passing by\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/wordley.com.au\/#website\",\"url\":\"https:\/\/wordley.com.au\/\",\"name\":\"Milton Wordley Photographer\",\"description\":\"Retired South Australian Photographer\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/wordley.com.au\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-AU\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/wordley.com.au\/#\/schema\/person\/e44f8fe828213224317d61638368d1b3\",\"name\":\"Duografik\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-AU\",\"@id\":\"https:\/\/wordley.com.au\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/e10f275260b341c8c5557300e1cdd3ae?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/e10f275260b341c8c5557300e1cdd3ae?s=96&d=mm&r=g\",\"caption\":\"Duografik\"},\"url\":\"https:\/\/wordley.com.au\/author\/duografik\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Time is passing by - Milton Wordley Photographer","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/wordley.com.au\/time-is-passing-by\/","og_locale":"en_US","og_type":"article","og_title":"Time is passing by - Milton Wordley Photographer","og_description":"Every selector has the potential to have unintended side effects by targeting unwanted elements or clashing with other selectors. More surprisingly, our selectors may even lose out in the global specificity war, ultimately having little or no effect on the page at all. Any time we make a change to a CSS file, we need to carefully consider the global environment in which our styles will sit. No other front end technology requires so much discipline just to keep the code at a minimum level of maintainability.","og_url":"https:\/\/wordley.com.au\/time-is-passing-by\/","og_site_name":"Milton Wordley Photographer","article_published_time":"2017-03-01T23:00:07+00:00","author":"Duografik","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Duografik","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/wordley.com.au\/time-is-passing-by\/","url":"https:\/\/wordley.com.au\/time-is-passing-by\/","name":"Time is passing by - Milton Wordley Photographer","isPartOf":{"@id":"https:\/\/wordley.com.au\/#website"},"datePublished":"2017-03-01T23:00:07+00:00","dateModified":"2017-03-01T23:00:07+00:00","author":{"@id":"https:\/\/wordley.com.au\/#\/schema\/person\/e44f8fe828213224317d61638368d1b3"},"breadcrumb":{"@id":"https:\/\/wordley.com.au\/time-is-passing-by\/#breadcrumb"},"inLanguage":"en-AU","potentialAction":[{"@type":"ReadAction","target":["https:\/\/wordley.com.au\/time-is-passing-by\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/wordley.com.au\/time-is-passing-by\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/wordley.com.au\/"},{"@type":"ListItem","position":2,"name":"Time is passing by"}]},{"@type":"WebSite","@id":"https:\/\/wordley.com.au\/#website","url":"https:\/\/wordley.com.au\/","name":"Milton Wordley Photographer","description":"Retired South Australian Photographer","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/wordley.com.au\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-AU"},{"@type":"Person","@id":"https:\/\/wordley.com.au\/#\/schema\/person\/e44f8fe828213224317d61638368d1b3","name":"Duografik","image":{"@type":"ImageObject","inLanguage":"en-AU","@id":"https:\/\/wordley.com.au\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/e10f275260b341c8c5557300e1cdd3ae?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/e10f275260b341c8c5557300e1cdd3ae?s=96&d=mm&r=g","caption":"Duografik"},"url":"https:\/\/wordley.com.au\/author\/duografik\/"}]}},"_links":{"self":[{"href":"https:\/\/wordley.com.au\/wp-json\/wp\/v2\/posts\/4229","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordley.com.au\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wordley.com.au\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wordley.com.au\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/wordley.com.au\/wp-json\/wp\/v2\/comments?post=4229"}],"version-history":[{"count":0,"href":"https:\/\/wordley.com.au\/wp-json\/wp\/v2\/posts\/4229\/revisions"}],"wp:attachment":[{"href":"https:\/\/wordley.com.au\/wp-json\/wp\/v2\/media?parent=4229"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wordley.com.au\/wp-json\/wp\/v2\/categories?post=4229"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wordley.com.au\/wp-json\/wp\/v2\/tags?post=4229"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}