Log in / Sign in

Lost password ?

0 0

No products in the wishlist.

View Wishlist

0 0
Shopping cart (0)
Subtotal: R0,00

Checkout

Free shipping over 49$
  • Home
  • About Us
  • Contact
  • Shop
  • Order Tracking
  • Home
  • About Us
  • Contact
  • Shop
  • Order Tracking
0 0
0 Shopping Cart
Shopping cart (0)
Subtotal: R0,00

Checkout

Free shipping over 49$
Return to previous page
Home Blog Business

Time is passing by

Business

Time is passing by

March 2, 2017 / 435 / 0

CSS selectors all exist within the same global scope. Anyone who has worked with CSS long enough has had to come to terms with its aggressively global nature — a model clearly designed in the age of documents, now struggling to offer a sane working environment for today’s modern web applications. 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. But it doesn’t have to be this way. It’s time to leave the era of global style sheets behind.

It’s time for local CSS.

In other languages, it’s accepted that modifying the global environment is something to be done rarely, if ever.

In the JavaScript community, thanks to tools like Browserify, Webpack and JSPM, it’s now expected that our code will consist of small modules, each encapsulating their explicit dependencies, exporting a minimal API.

Yet, somehow, CSS still seems to be getting a free pass.

Many of us — myself included, until recently — have been working with CSS so long that we don’t see the lack of local scope as a problem that we can solve without significant help from browser vendors. Even then, we’d still need to wait for the majority of our users to be using a browser with proper Shadow DOM support.

We’ve worked around the issues of global scope with a series of naming conventions like OOCSS, SMACSS, BEM and SUIT, each providing a way for us to avoid naming collisions and emulate sane scoping rules.

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 — unlike the traditional global selector model—wouldn’t produce any naming collisions.

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

The benefits of global CSS — style re-use between components via utility classes, etc. — are 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’t make many, if any, assumptions about the global environment.

Writing maintainable CSS is now encouraged, not by careful adherence to a naming convention, but by style encapsulation during development.

Once you’ve tried working with local CSS, there’s really no going back. Experiencing true local scope in our style sheets — in a way that works across all browsers— is not something to be easily ignored.

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’re only at the beginning of this new era of local CSS.

process.env.NODE_ENV === 'development' ?
    '[name]__[local]___[hash:base64:5]' :
    '[hash:base64:5]'
)

Understanding the ramifications of this shift is something that we’re still working through. With your valuable input and experimentation, I’m hoping that this is a conversation we can have together as a larger community.

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.

Tags: Tech, Life, Sport, Travel
Share Post
How to Style a Quiff
The details make the design

Related posts

Arts
Read more

Inspired by clouds

March 22, 2017 / 481 / 0
Last year I wrote about why booking too far in advance can be dangerous for your business, and this concept of margin so eloquently captures... Continue reading
Business
Read more

Make it clean and simple

March 20, 2017 / 509 / 0
Just the other day I happened to wake up early. That is unusual for an engineering student. After a long time I could witness the... Continue reading
Business
Read more

Sounds from the streets

January 28, 2017 / 395 / 0
Last year I wrote about why booking too far in advance can be dangerous for your business, and this concept of margin so eloquently captures... Continue reading
Arts
Read more

Working from your home?

January 14, 2017 / 410 / 0
Just the other day I happened to wake up early. That is unusual for an engineering student. After a long time I could witness the... Continue reading
Business

Awwwards best websites

January 8, 2017 / 376 / 0
I was recently quoted as saying, I don't care if Instagram has more users than Twitter. If you read the article you’ll note there’s a... Continue reading

Leave a reply Cancel reply

Your email address will not be published. Required fields are marked

Recent Posts

  • Hello world!
  • Calm over the horizon
  • Inspired by clouds
  • Make it clean and simple
  • When you are alone

Recent Comments

No comments to show.

Archives

  • July 2023
  • March 2017
  • February 2017
  • January 2017
  • March 2016
  • February 2016
  • January 2016
  • October 2015

Categories

  • Uncategorized
  • Lifestyle
  • Arts
  • Travel
  • Business
  • Markup
  • News & Announcements
  • Trends & Cravings
  • Featured
  • Vegetables
  • Work
  • Interactive
  • Music & Style

FREE TEXT

Energistically benchmark focused growth strategies via superior supply chains. Compellingly reintermediate mission-critical potentialities whereas cross functional scenarios. Phosfluorescently re-engineer distributed processes without standardized supply chains.

RECENT POSTS

  • Hello world!
  • Calm over the horizon
  • Inspired by clouds
  • Make it clean and simple
  • When you are alone

CATEGORIES

  • Uncategorized
  • Lifestyle
  • Arts
  • Travel
  • Business
  • Markup
  • News & Announcements
  • Trends & Cravings
  • Featured
  • Vegetables
  • Work
  • Interactive
  • Music & Style

META

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org

Menu

  • Home
  • About Us
  • Contact
  • Shop
  • Order Tracking
November 2026
M T W T F S S
 1
2345678
9101112131415
16171819202122
23242526272829
30  
« Jul    
  • Facebook
  • Instagram
  • Mail
© Created by  8theme - Power Elite ThemeForest Author.
Home
Shop
0 Wishlist
More
More
  • Main Portfolio
  • Blog Archive
  • About Us
  • Contact Us
  • Privacy Policy