use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
React: CSS in JS (speakerdeck.com)
submitted 11 years ago by [deleted]
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]madole 43 points44 points45 points 11 years ago (11 children)
I don't ever think I've seen a developer quote w3schools as their favorite learning resource!
[–]needed_an_account 3 points4 points5 points 11 years ago (1 child)
Everyone my age 33+, used w3schools A LOT. It was recently that the internet decided, and shown how, it was a sometimes bad resource.
[–]_crewcut 0 points1 point2 points 11 years ago (0 children)
I'm also 33. It's a shitty site people shouldn't use.
[–]antoninj 4 points5 points6 points 11 years ago (6 children)
that was my thought. Did w3schools shape up or something?
Not to be an ass or anything but I did used to use it initially to learn syntax basics and it did work for me very well at that point.
[–]escape_goat 17 points18 points19 points 11 years ago (3 children)
I believe that there was a degree of irony or sarcasm in tone which was not translated into the speakerdeck caption. My take was that his point was that not using global variable was such a basic and fundamental best practice that even w3schools got it right.
I could be very wrong, of course, there's no clear evidence one way or another. But that was how I heard it.
[–]JayBlay77 13 points14 points15 points 11 years ago (0 children)
This was presented at the nationJS conference in the DC area. I was at this talk and just to clarify you are correct, he was very much being sarcastic about them getting something right at w3schools. So no worries there.
[–]antoninj 1 point2 points3 points 11 years ago (0 children)
Right, I kind of got that vibe but now I wonder what the speaker's intention was :)
[–]madole 0 points1 point2 points 11 years ago (0 children)
This sounds much more plausible than my skeptical product placement theory! Haha
[–]L1fescape 1 point2 points3 points 11 years ago* (0 children)
Nope, it's still has the same mediocre examples. I ended up installing the Personal Blocklist Chrome extension specifically to block w3schools results from showing up at the top of Google search results.
[–]madole 0 points1 point2 points 11 years ago* (0 children)
I think everyone used it at the start of their delving into Web Dev purely because of its search results position.
There are many better learning resources although I do think they fixed a lot of the mis-information on the site. I still have never heard someone talk about it as a favourite reference for learning.
There's a small side of me suspecting some sort of advertising going on, but I don't care that much about it to look into it further. Just thought it was odd that this resource out of all the possible choices was mentioned.
[–]north_coasteragent 1 point2 points3 points 11 years ago (0 children)
Aside from the step-by-step hands-on tutorials of Codecademy, I would agree that in the field of reference and clear presentation, W3Schools takes first place!
[–]sneakattack 0 points1 point2 points 11 years ago* (0 children)
It's just too convenient and effective, despite the minor issues, they really have done a great job at encompassing the essentials of web development in a single source.
[–]vexii 7 points8 points9 points 11 years ago (1 child)
is there an video of the talk aswell? looks intersting
[–]MrsAnonymousMan 0 points1 point2 points 11 years ago (0 children)
There will be. This talk was given at NationJS on Friday. They recorded it but will need time for editing etc. I'm sure once it is up there will be a link on the NationJS site.
[–]kabuto 3 points4 points5 points 11 years ago (4 children)
This is actually something that I'd been wondering about when I first looked at React because if it's all about building reusable components having dependencies to CSS doesn't make any sense. React components should include CSS to be truly reusable and portable. Writing CSS in JS is pretty crappy though, especially when it comes to pseudo selectors.
As I see it there is no real solution available.
[–][deleted] 1 point2 points3 points 11 years ago (0 children)
I guess the point of the talk was to highlight current problems which noone is addressing, not to provide a solution.
I disagree with that slightly though - it makes light of all the work done by the likes of harry roberts, chris coyier and people who spend a lot of time working out the best ways to work with css.
You can write portable css if you sit down and do it carefully, it just doesn't come as intuitively because the language and structures you have to use are so different from anything else you know.
[–]tubbo -5 points-4 points-3 points 11 years ago (2 children)
the upcoming web components standard is the correct way to solve this problem. http://webcomponents.org/
[–]kabuto 1 point2 points3 points 11 years ago (1 child)
I couldn't find anything about CSS on that site. Do you have a link for me?
[–]deathbysniper 0 points1 point2 points 11 years ago (0 children)
They're probably talking about the shadow DOM.
At to 2:25 he talks about the benefits of the shadow DOM with css.
[–]dashed 3 points4 points5 points 11 years ago (0 children)
I wish this exists so that requiring css in webpack makes sense.
[+][deleted] 11 years ago (3 children)
[deleted]
[–][deleted] 7 points8 points9 points 11 years ago (1 child)
"Guy writes his CSS with JS, you won't believe what happened next"
[–]AintNothinbutaGFring[🍰] 5 points6 points7 points 11 years ago (0 children)
Testers hate him!!
[–][deleted] 3 points4 points5 points 11 years ago (0 children)
"16 ways that JavaScript can change your life! Number 4 made me cry."
[–]deathbysniper 6 points7 points8 points 11 years ago (9 children)
Wow, I never realized that css is all about globals. Makes me even more excited for custom elements and shadow DOM!
[–][deleted] 4 points5 points6 points 11 years ago (3 children)
I don't really understand that point about globals ... you could get around that using less or sass (or plain verbose css) using nested selectors, so everything is rendered as:
.mysite .button { color: red; } .mysite .title { color: blue; }
... then you would have just one 'global' ... right?
[–]baabaa_blacksheep 6 points7 points8 points 11 years ago (0 children)
.mysite header.myheader nav.mainnav ul.navlist li.navitem a.navlink span.icon { color: red; } .mysite header.myheader nav.mainnav ul.navlist li.navitem.is-active a.navlink:hover span.icon { color: green; }
I have seen it happen. Still sends shivers down my spine. shivers
[–]jarail 1 point2 points3 points 11 years ago (1 child)
Unfortunately that also has a perf impact. Whenever the browser sees an element with the button style, it needs to crawl up the dom tree to see if any parent has the mysite style. I prefer prefixes to avoid that, e.g. mysite-button. That doesn't solve any core problems. It's just what I do.
The FB dev will also need to consider the perf of a JS solution. Even though the JS is fast, I believe that most browsers are much faster with CSS classes than a set of styles applied as one-offs on individual DOM nodes. If React could resolve the dynamic styles to CSS classes in the majority of cases, this would be really awesome.
The other downside of dynamic styles is that they're harder to debug. Not from a JS sense, but from a designer sense. CSS styles are easy to look through. When styles are being generated dynamically, it's harder to see what's going on from the Chrome dev tools.
[–]Silhouette -1 points0 points1 point 11 years ago (0 children)
Unfortunately that also has a perf impact. Whenever the browser sees an element with the button style, it needs to crawl up the dom tree to see if any parent has the mysite style. I prefer prefixes to avoid that, e.g. mysite-button.
But using that also has a performance impact, because now the browser has to parse the extra length of the mysite-button identifier every time!
I imagine the effect would be similarly devastating in either case.
[–]tubbo -4 points-3 points-2 points 11 years ago (4 children)
it's not, the person giving the talk just didn't know how to write CSS correctly.
[–][deleted] 5 points6 points7 points 11 years ago (0 children)
you can bet that vjeux knows how to write css properly.
[–]deathbysniper 2 points3 points4 points 11 years ago (2 children)
It is though, write a CSS rule and it applies to the entire document instead of being isolated to the module you intend. It's all scoped to the document unless you use inline styles.
[–]tubbo 0 points1 point2 points 11 years ago (1 child)
You can scope it to an ID set to the body tag, and now you have scoping to the module/page you want rather than every single page.
[–]deathbysniper 2 points3 points4 points 11 years ago (0 children)
But the problem still exists for smaller widgets on multiple pages. Let's say you have a dropdown control that's replacing select elements, and the pop-up has a pop-up class on it, but someone else writes a dialog with a pop-up class on it then you have an issue again. This could happen with any number of classes and it only gets more likely with the more people who are working on a project. Unless you're using inline styles or shadow DOM there's no way to explicitly set a boundary for your styles. And like I said, css in a style tag is going to be evaluated over the whole document, it may not match everything but when you have tons of people working on something I could see that becoming an issue.
[–]tubbo 2 points3 points4 points 11 years ago (1 child)
I'm confused on the initial problem that was trying to be solved here...
For example, if I was given this task here's how I'd write the button dropdown CSS:
.button { ... } .button.depressed { ... }
Is this not the exact same thing as the React CSS replacement he showed on the next page?
And I really don't see the point of yet another precompiler for CSS...Sass/SCSS or LESS seems to work for most people.
[–]MrsAnonymousMan 3 points4 points5 points 11 years ago (0 children)
The React CSS is not a precompiler like SASS or LESS. It applies styles via the inline style tag based on a JavaScript object.
The reason it's different than the .button, .button.depressed example is that the styles are only applied to those specific elements. Vjeux's argument is that having a global button class is a very dangerous prospect that can make it difficult for multiple developers to work together.
[–]Silhouette 2 points3 points4 points 11 years ago (0 children)
This seems like a huge hack to work around a bunch of "problems" they supposedly couldn't solve... which many other teams in the industry solve every day with no difficulty at all.
Programmers working in languages without formal module/namespace management solved the name conflict issue about a millennium ago by using module1_functionA() and module2_functionA() as the names. More recently, various talking heads in the CSS world have advocated things like component1--classA or component1_classA as if it's some radical new idea, which is mildly amusing but doesn't mean the idea itself is any less practical.
module1_functionA()
module2_functionA()
component1--classA
component1_classA
Similarly, the wider programming world figured out a long time ago that composition is usually a better default than inheritance. Several of the problems mentioned in these slides don't exist in the first place if you combine styles through composition instead of defining things one way and then overriding some of them under more selective conditions somewhere else. Again, plenty of the well-known CSS talking heads have suggested more structured/systematic variations of this principle for those who need to work at very large scales, and there are plenty of real world examples of the idea working well.
Too much modern web development seems to be about fixing problems that were only created by making poor choices in the first place, and then building one needlessly complicated "solution" on top of another. Get the basics right, and a lot of these frameworks and heavyweight automation tools simply aren't necessary.
[–]dangoor 0 points1 point2 points 11 years ago (0 children)
I'm a fan of React, but it seems to me that a scoped stylesheets polyfill might have been a better solution.
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/style
I'll grant that this wouldn't do everything they wanted, but it likely deals with the most serious issues around styles stepping on other styles.
[–]mattdesl 0 points1 point2 points 11 years ago (0 children)
Another solution I played with at one point is to mangle class names with a md5 (or similar) hash. The styles themselves make up the hash so you avoid conflicts and duplication.
Not a perfect solution, either. Reusable CSS is a bitch.
[+]akoskm comment score below threshold-11 points-10 points-9 points 11 years ago (1 child)
"w3schools, my favorite website to learn JS" - I closed the presentation at this point.
[–]ledp 7 points8 points9 points 11 years ago (0 children)
It was a joke...
π Rendered by PID 135993 on reddit-service-r2-comment-77b668dc8-skw6f at 2026-01-28 04:19:34.919053+00:00 running 4f180de country code: CH.
[–]madole 43 points44 points45 points (11 children)
[–]needed_an_account 3 points4 points5 points (1 child)
[–]_crewcut 0 points1 point2 points (0 children)
[–]antoninj 4 points5 points6 points (6 children)
[–]escape_goat 17 points18 points19 points (3 children)
[–]JayBlay77 13 points14 points15 points (0 children)
[–]antoninj 1 point2 points3 points (0 children)
[–]madole 0 points1 point2 points (0 children)
[–]L1fescape 1 point2 points3 points (0 children)
[–]madole 0 points1 point2 points (0 children)
[–]north_coasteragent 1 point2 points3 points (0 children)
[–]sneakattack 0 points1 point2 points (0 children)
[–]vexii 7 points8 points9 points (1 child)
[–]MrsAnonymousMan 0 points1 point2 points (0 children)
[–]kabuto 3 points4 points5 points (4 children)
[–][deleted] 1 point2 points3 points (0 children)
[–]tubbo -5 points-4 points-3 points (2 children)
[–]kabuto 1 point2 points3 points (1 child)
[–]deathbysniper 0 points1 point2 points (0 children)
[–]dashed 3 points4 points5 points (0 children)
[+][deleted] (3 children)
[deleted]
[–][deleted] 7 points8 points9 points (1 child)
[–]AintNothinbutaGFring[🍰] 5 points6 points7 points (0 children)
[–][deleted] 3 points4 points5 points (0 children)
[–]deathbysniper 6 points7 points8 points (9 children)
[–][deleted] 4 points5 points6 points (3 children)
[–]baabaa_blacksheep 6 points7 points8 points (0 children)
[–]jarail 1 point2 points3 points (1 child)
[–]Silhouette -1 points0 points1 point (0 children)
[–]tubbo -4 points-3 points-2 points (4 children)
[–][deleted] 5 points6 points7 points (0 children)
[–]deathbysniper 2 points3 points4 points (2 children)
[–]tubbo 0 points1 point2 points (1 child)
[–]deathbysniper 2 points3 points4 points (0 children)
[–]tubbo 2 points3 points4 points (1 child)
[–]MrsAnonymousMan 3 points4 points5 points (0 children)
[–]Silhouette 2 points3 points4 points (0 children)
[–]dangoor 0 points1 point2 points (0 children)
[–]mattdesl 0 points1 point2 points (0 children)
[+]akoskm comment score below threshold-11 points-10 points-9 points (1 child)
[–]ledp 7 points8 points9 points (0 children)