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.
Howdy! I know this is somewhat off-topic however I needed to ask.
Does building a well-established website like yours require a lot of work?
I’m brand new to writing a blog but I do write in my journal on a
daily basis. I’d like to start a blog so I will be able to share my experience and views online.
Please let me know if you have any suggestions or tips for brand new
aspiring blog owners. Thankyou!
Hi there it’s me, I am also visiting this web site daily,
this site is actually nice and the viewers are in fact sharing
good thoughts.
Hello, I want to subscribe for this website to get most up-to-date updates, so where can i do it please
help out.
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.
great article
digiyumi.com
Fang Xiaofan은 깜짝 놀랐습니다. « 저를 비난하지 마세요. 형이 그렇게 말하라고 했어요. »
baseballoutsider.com
그는 갑자기 자신이 너무 온화하고 얼굴이 매우 추악하다고 느꼈습니다.
this-is-a-small-world.com
이 모든 것이… 이 지독한 소리와 톡 쏘는 냄새로 망가졌다.
agonaga.com
Fang Jifan은 « 나중에 전하가 먼저 사과하러 갈 것입니다. « 라고 편리하게 말했습니다.
rivipaolo.com
결정적인 순간에 항상 일어서서 스스로를 대변하는 사람은 누구입니까?
Insightful piece
great article
saungsantoso.com
이 소리에 놀란 그는 거의 비틀거릴 뻔했다.
restaurant-lenvol.net
이것들은 원래 마을의 노인들로부터 구전으로 전해졌습니다.
digiapk.com
Liu Jian과 다른 사람들은 절을하며 « 폐하 … 안전하십니까? « 라고 말했습니다.
10yenharwichport.com
그것은 단지 … 이번 베이징 시찰도 Fang Jifan이 대중의 불만을 불러 일으켰습니다.
10yenharwichport.com
이에 대해 주담지의 얼굴은 유난히 엄숙해졌다.
doeaccforum.com
그렇게 말하면서 그녀는 Fang Jifan의 눈을 의미있게 교차했습니다.
chasemusik.com
공중에서 꼬리 불꽃이 붙은 포탄은 스페인 팔랑크스를 향했다.
socialmediatric.com
Fang Jifan은 고개를 끄덕였고 Li Chaowen은 천천히 일어나 이불에 다시 앉았습니다.
azond8
pragmatic-ko.com
하지만 이때 Fang Jifan은 여유롭게 말했다. « 잠깐만, 할 말이 있어요. »
dota2answers.com
이렇게 말하면 Fang Jifan과 Zhu Houzhao는 나를보고 나는 당신을 봅니다.
smcasino-game.com
그는 Ouyang Zhi를 돌아보며 « 당신이 와서 그를 위로하십시오. »
lfchungary.com
Deng Jian은 그의 머리를 잡고 « 스승님, 당신이 저에게 이것을 가르쳐 주셨습니다 … »Deng Jian은 « 젊은 주인을 섬기던 악당처럼? »
hihouse420.com
Jiang Chen과 Liu Wenshan은 감정의 동요 없이 고개를 숙였습니다.
lfchungary.com
내시는 조심스럽게 촉구했지만 Zhu Houzhao는 « Xinjian 삼촌을 기다리고 있습니다. « 라고 말했습니다.
pragmatic-ko.com
Zhu Houzhao는 서둘러 말했습니다. « 얼마나 많은 음식을 가져 오셨습니까 … »
chutneyb.com
과거 왕조에서 특별한 취미를 가진 황제들 중 어느 누가 희미한 황제가 되지 않았습니까?
sm-online-game.com
아시다시피 황제 주변의 위대한 환관들은 단순히 사람들을 섬기는 것이 아닙니다.
pragmatic-ko.com
Hongzhi 황제는 Fang Jifan이 « 믿다 »라는 단어를 내놓는 것을 들었습니다.
lfchungary.com
이런 부주의한 사람들이 어찌 조상에게 제사를 드릴 수 있겠습니까?
I like reading a post that can make people think. Also, thanks for allowing me
to comment!
lfchungary.com
Fang Jifan은 일어 서서 « 빨리, 빨리, 흰 코트를 찾아주세요. « 라고 신나게 말했습니다.
strelkaproject.com
하지만… 목이 차가워서 감히 거절할 수가 없었다.
Conclamatum est — Всё кончено, всё погибло.
pragmatic-ko.com
물론 질문을 빗는 것 외에도 사람들이 토하고 싶게 만듭니다.
pactam2.com
많은 사람들의 얼굴이 감동을 받았고, 눈가에는 약간의 습기가 차 있었습니다.
sm-casino1.com
그의 말투는 게으르지만 Fang Jifan의 마음은 극도로 긴장했습니다!
shopanho.com
« 폐하, 지금은 날카로운 칼날을 피하고 나중에 공격해야 합니다… »
apksuccess.com
Fang Jifan은 진지하게 말했습니다. « 학생 중 Xu Jing은 자격이 가장 나쁜 사람입니다. »
sm-online-game.com
먼저 그는 마차를 타고 홍치제를 만나기 위해 장소로 갔다.
parrotsav.com
Wu Zhong은 마음에 약간의 고통을 느꼈고 너무 화가 나서 폭발하려고했습니다.
yangsfitness.com
« 이게 사공의 필체인가요? » 장마오는 의심스러운 눈으로 샤오징을 바라보았다.
apksuccess.com
Zhu Houzhao는 정신을 차리고 « 이 사업가들은 정말 믿음이 없습니다 … »라고 말했습니다.
l-inkproject.com
국정 제패라면 이것의 백 배는 넘지 않을까 두렵다.
order lipitor 40mg sale order lipitor 20mg pill atorvastatin medication
buy cipro 500mg pills – cipro 1000mg tablet augmentin 375mg brand
twichclip.com
이렇게 분주한 모습을 본 홍지황제는 감격의 한숨을 쉬지 않을 수 없었다.
sm-casino1.com
Wang Shouren은 마치 적과 마주한 것처럼 긴장된 상태로 Fang Jifan을 따랐습니다.
mikschai.com
따라서 사람들은 질병을 치료하기 위해 복용량을 늘려야 합니다.
This piece of writing offers clear idea in favor of the new people of blogging, that
truly how to do running a blog.
buy ciprofloxacin 500mg for sale – buy doryx online buy erythromycin 500mg generic
metronidazole 400mg usa – where to buy clindamycin without a prescription zithromax drug
sm-online-game.com
우리 모두가 알다시피 그는 감히 닭과 소도 죽이지 않는 착한 사람입니다.
jelenakaludjerovic.com
« 그럼 내일 동이 트기 전에 여기 도착하면 되나… »
Aw, this was a very good post. Taking the time and actual effort to
create a great article… but what can I say… I procrastinate a
whole lot and don’t seem to get nearly anything done.
ivermectin 3 mg otc – buy aczone pills for sale buy sumycin 500mg sale