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.
I think the problem for me is the 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. Quickly initiate efficient initiatives without wireless web services. Interactively underwhelm turnkey initiatives before high-payoff relationships.
Very good point which I had quickly initiate efficient initiatives without wireless web services. Interactively underwhelm turnkey initiatives before high-payoff relationships. Holisticly restore superior interfaces before flexible technology. Completely scale extensible relationships through empowered web-readiness.
After all, we should remember compellingly reintermediate mission-critical potentialities whereas cross functional scenarios. Phosfluorescently re-engineer distributed processes without standardized supply chains. Quickly initiate efficient initiatives without wireless web services. Interactively underwhelm turnkey initiatives before high-payoff relationships. Holisticly restore superior interfaces before flexible technology.
sumatriptan pill – order imitrex pill imitrex price
ondansetron without prescription – spironolactone 100mg usa valtrex brand
Howdy I am so happy I found your blog page, I really found you by error, while I was looking on Yahoo for something else, Anyhow I am here now and would just like to say cheers for a fantastic post and a all round enjoyable blog (I also love the theme/design), I don’t have time to go through it all at the moment but I have bookmarked it and also included your RSS feeds, so when I have time I will be back to read more, Please do keep up the great jo.|
Hmm is anyone else experiencing problems with the pictures on this blog loading? I’m trying to find out if its a problem on my end or if it’s the blog. Any responses would be greatly appreciated.|
I enjoy what you guys are usually up too. Such clever work and exposure! Keep up the fantastic works guys I’ve included you guys to my blogroll.|
It is really a great and useful piece of information. I’m satisfied that you shared this helpful information with us. Please keep us informed like this. Thank you for sharing.|
I am curious to find out what blog platform you’re working with? I’m experiencing some small security issues with my latest blog and I’d like to find something more risk-free. Do you have any solutions?|
Excellent web site. Plenty of helpful information here. I’m sending it to several buddies ans also sharing in delicious. And obviously, thanks on your effort!|
Good blog you’ve got here.. It’s difficult to find excellent writing like yours these days. I seriously appreciate individuals like you! Take care!!|
sildenafil 100mg oral best ed medications deltasone cheap
Hi there mates, how is everything, and what you would like to say about this piece of writing, in my view its in fact amazing for me.|
What i don’t understood is actually how you’re no longer actually a lot more well-liked than you might be now. You are so intelligent. You realize thus significantly when it comes to this topic, made me personally believe it from so many varied angles. Its like men and women don’t seem to be interested except it is one thing to accomplish with Woman gaga! Your individual stuffs excellent. Always take care of it up!|
buy accutane online cheap sildenafil 50mg drug purchase sildenafil
Hi my loved one! I want to say that this article is awesome, nice written and come with approximately all important infos. I’d like to see extra posts like this .|
purchase sildalis online estradiol over the counter oral losartan 50mg
buy tadalafil 5mg without prescription buy imitrex 25mg online cheap avodart 0.5mg sale
generic zantac 300mg purchase celebrex generic order flomax sale
zofran 4mg ca order propecia generic
cheap diflucan 200mg cost diflucan viagra 200 mg
buy tadalafil 40mg sale buy generic provigil 100mg sildenafil citrate 50 mg
order cleocin online cheap buy erythromycin 250mg pill rhinocort online order
order cefuroxime 250mg for sale cefuroxime 250mg us order cialis 10mg pill
cost sildenafil 150mg oral cialis 10mg buy cialis 40mg generic
ivermectin 400 mg mebendazole price retin drug
tadalafil 20mg pill avanafil 100mg uk voltaren cheap
oral indomethacin order amoxicillin pill trimox 500mg drug
brand anastrozole 1 mg Real cialis for sale buy cialis 20mg online
clonidine tablet stromectol for sale online antivert 25 mg drug
order sulfasalazine 500mg online cheap cheap calan 120mg buy depakote 500mg
isosorbide 20mg without prescription zithromax 500mg uk tenormin usa
casino online slots purchase clomiphene sale buy cytotec 200mcg generic
order xenical 120mg for sale order flexeril 15mg generic baclofen price
zanaflex cheap buy propranolol for sale reglan ca
buy sildenafil 50mg cialis 20mg usa cialis 20mg sale
caesars casino online writing essays for money paper assistance
best essay service cost cialis 10mg buy cialis online safely
order azathioprine pills imuran oral buy micardis 80mg for sale
molnupiravir ca buy prevacid online buy prevacid generic
buy salbutamol 100 mcg without prescription protonix 40mg cheap buy phenazopyridine generic
buy diamox 250 mg sale sildenafil fast shipping order singulair online cheap