12 ms·
CSS in JavaScript is like replacing a broken screwdriver with your favorite hammer
- onion-soup 9y agoOh stop bashing on CSS in JS already. It's not CSS in JS, it's CSS in component files which are -- surprise surprise -- VIEW FILES. I see nothing wrong with having dimensional and visual definitions in view files, their whole point of existence is to serve as such. You are trying to solve a problem that doesn't exist.
- vlunkr 9y agoI don't think you've contested any of the authors arguements here. They argue that inline styles are difficult to maintain and refactor, because of the tendency to copy-paste. Also to implement hover or other styles, you have to go back to CSS or use JS which is much worse. Also, it's not CSS, it's inline styles, and you lose the cascading advantage. Say I want every anchor tag on my site to be the same color, without CSS I have to go stick that style on every one individually. Realistically you would make it component, but it's a component that wouldn't need to exist with just one line of CSS. I'm sure it's possible to write in this way correctly, but every time I've seen it it's been awful. But that probably has more to do with the fact that the devs writing it really didn't care much to write clean styles. I'm not saying CSS is definitively better, that's just my opinion. But if you are going to advocate inline styles you have to know the trade offs and be able to justify them.
- k__ 9y agoThe copy-paste problem is true. But on the other hand, I often end up with a few "primitive" base components that use CSS-in-JS and reuse these components. So I have a few components with "inline" styles and the rest uses these components. For a refactor I simply have to change these components.
- onion-soup 9y ago>you lose the cascading advantage What? Components and cascading? Only inline styles make sense if we are talking components. Each component must be self-contained, pure and predictive. Why the hell do we want 90s technology again?
- Pxtl 9y agoThis. You can have global styling, or you can have properly-encapsulated components. The more you try to have it both ways, the more they step on each other's toes. And for me personally, at least for heavy-duty web applications, modular components are far more useful.
- talmand 9y agoYou can do component-based, self-contained CSS without inline styles. I would recommend you not use inline styles when it's easy enough to do what you want the CSS way.
- geon 9y ago> inline styles It doesn't have to be inline styles. Styled components ( https://www.styled-components.com/ https://www.styled-components.com/ ) inject unique css classes.
- breeny592 9y agoAmong many other solutions as well (like JSS). CSS-in-JS !== inline styles, at all, yet seems to be a rallying call for people who fear "something different".
- wvenable 9y ago> Say I want every anchor tag on my site to be the same color But you don't. You have a popup calendar component and none of it's links are supposed to be colored at all. The problem isn't that anyone is wrong here; it's that there are actually multiple things going on here and depending on where you felt the pain last is where your opinion might fall. I use a lot of 3rd party components that have their own styling and attempting to affect that globally is disastrous for them. But I'm also rolling out an entirely new style and layout for all our applications and I'm not changing the code -- it's almost entirely global CSS changes. Sometimes it's hard to reconcile these two things.
- GlennS 9y agoI think in practice, the 'cascading' aspect of CSS turned out to be a bad idea. Most people seem to find that, rather than providing the consistent theming it promises, automatic inheritance of properties is confusing and unpredictable. Better to manage consistency through explicit includes of constants instead.
- StillBored 9y agoRight, because there is a difference between styling and layout for non-trivial pages. CSS really should have added a "disable cascade" global flag when they introduced variables. Of course that is how people have been using less/sass for a decade+ now too.
- talmand 9y agoI'm intrigued by this idea that people have been using less/sass for some time now without cascading?
- StillBored 9y agoWell, I can see how I implied that, I meant only to say that it allows (and that is how I used it, and the couple times I saw others using it) one to define common properties as variables/mixins and ignore the cascading. Of course the result is cleanly written style sheets, but the output is a mass of duplicated code.
- talmand 9y agoI see now. In that case your source code is tidy and the mass of duplication in the output is not so bad while accounting for gzip. It's best to account for cascading and take advantage of it when suitable. But sometimes a project can just get away from you doing that and you may be better off doing what you're saying. It all depends on the project. Most of the talk on this page about styling components would result in mass duplication of code. But that might be best for their project.
- braindouche 9y ago> you lose the cascading advantage while at the same time you maintain the cascading disadvantages. You can't prevent CSS from cascading unless all your styles are inline, or you've OOCSSed your project so thoroughly that you've used classes to recreate inline styles.
- nicodjimenez 9y agoYeah I'm really sick and tired of seeing these articles that add no value. Nothing has added more value in front end development in the last 5 years more than using JS for more and more of the view logic so why stop at HTML?
- n0us 9y agohttps://github.com/styled-components/styled-components https://github.com/styled-components/styled-components strikes a really nice balance here imo. I use Radium every day and in general it has been easier to maintain and use in comparison to all css but if I could do it again I would go with styled-components.
- HugoDaniel 9y agoHow many of people that argument in favor of the CSS in JS know about the Atomic CSS approach ? It is currently the best of both worlds, you can control it with JS in a proper semantic way (through class setting) while keeping 0% replication and loose coupling between concepts. It also is easily extensible and composes very well. The downsides are that your CSS file is going to be a bit bigger than usual (tachyons.io with all modules goes about 84KB uncompressed, 17KB gziped). But that can be quite irrelevant in big JS oriented projects where most of the size is occupied by big libs.
- reaperducer 9y agoAn 84K CSS file. Well, I guess that's one way to get fired.
- HugoDaniel 9y agoYes, but that is all the CSS you will ever need to have. If you assume an average of 2.3MB[0] on the common page, that is about 3% of your project size for CSS that will not grow past that (atomic approach implies that you won't change it as we add more styles to your page(s)). [0] https://www.keycdn.com/support/the-growth-of-web-page-size/ https://www.keycdn.com/support/the-growth-of-web-page-size/
- talmand 9y ago>> Yes, but that is all the CSS you will ever need to have. Just make sure everybody else in the company is on board with that thought.
- haukur 9y agoIf you're interested in this approach, check out Pete Hunt's jsxstyle or Kent C Dodds' glamorous. Both allow you to pass in props that map to css rules (e.g., `<Flex justifyContent="center" />`).
- HugoDaniel 9y ago
- ddoolin 9y agoI think Vue's single-file component approach is a good solution here, allowing you to keep all three separate but in the same file with the additional option to keep the CSS scoped and add a preprocessor to it. https://vuejs.org/v2/guide/single-file-components.html https://vuejs.org/v2/guide/single-file-components.html About CSS in JS, though, it mostly just seems like a different way of getting the same thing on the page, changed only by the idea of scoping it to some component and maybe some needed flexibility when building dynamic CSS rules. I'm still not convinced any of those CSS approaches propped by the author are necessary or even necessarily that helpful. They can be confusing to developers not familiar with it and burdensome when truly not needed. I'm open to other opinions, though.
- deleted 9y ago[deleted]
- codegeek 9y agoI am really digging Vuejs and its single file components. The <style scoped> part makes it even better for me. No more searching through codebase for where the css came from vs. where the JS is coming from.
- Barreljack 9y agoAgreed. I really enjoy the way Vue handles this.
- madeofpalk 9y agoJust going to chime in with 'CSS Modules' - this approach of scoped-css generalised to use with whatever framework (but most commonly, React)
- orillian 9y agoI'm going to nth this! I really enjoy Vue's way of managing these separate but together.
- werber 9y agoI completely agree, I put global styles in my front most component and scoped ones in smaller very specific ones. It's been a really great change for my workflow.
- joshribakoff 9y agoThis is like when everyone complained when angularjs put ng-click in the template instead of an .on(click) in the js. It increased productivity because I no longer had to do searches of the codebase to check if there are event listeners. I can just see that by looking at my template
- throwawayReply 9y agoIf your solution is "better practices", you don't have a solution. In the real world, people will migrate to what works for keeping people inline. Appealing to better practice will be mowed down by actual practice. Instead write tools which encourage better practice.
- hacker_9 9y agoThe argument here is that CSS should be kept seperate because it is just the design and doesn't affect the behaviour. But this really isn't true. Want to create dropdown menus or tabcontrols? HTML just isnt enough, you need a whole set of styles in order to even create these controls. Additionally why am I able to do animation in CSS? Or insert new HTML elements?? This thing has grown far beyond simple colour switching and changing font sizes. In fact the seperation causes so much mental overhead, that we need interactive browser dev tools just to be able to find what styles are applied to what element. So ultimately the idea of putting everything in one spot, per component, is actually pretty reasonable.
- ballenf 9y agoAgreed. To take the author's metaphor a step further: the reason the screwdriver was broken is because we're trying to use it as a hammer. So replacing it with an actual hammer makes sense. And the thing is, we still have a fully functional screwdriver at our disposal (for global styles, e.g.).
- jerf 9y agoThe metaphor is fundamentally broken anyhow. Hammers and screwdrivers are the same class of things. CSS and JS are not. One is a non-Turing-complete [1] language for declaring properties based on matching criteria. The other is a full programming language. Since metaphors are worse than useless when you already understand the thing, and I think we all understand the things in question, I won't find a better one. I'll just point out the original one is useless. I've considered JS taking over CSS more and more thoroughly inevitable for about four years now. The pressures on CSS are just too intense for non-Turing completeness to be anything but a leftover remnant of the dream of the "Semantic" web, doomed to fade the same way [2]. People want what only hooking a programming language up to the layout engine is going to give them. You can see it in CSS itself, as it grows ever more "declarative" styles that involve introspecting into the elements themselves, at their content, at their position in the tree, at their siblings.... CSS has long since let the camel into the tent. (In fact per my earlier comment today, https://news.ycombinator.com/item?id=15218359 https://news.ycombinator.com/item?id=15218359 , I would consider even CSS-in-JS to still be an intermediate phase to where we're truly going.) As for the fact that it will be a mess... well... yeah, it will. Welcome to the web. [1]: I know about the "Turing complete" CSS. It requires user interaction. Cute, but nothing more. [2]: "What? The semantic web is stronger than ever! Just look at what Google does with its search results!" ... which is a mix of some ad-hoc tags that are rarely the RDF tags the Semantic Web vision was based on, and a whole whackload of machine learning and language analysis. The Semantic Web vision was fundamentally that we can just hand tags out and everybody in the world will eagerly and accurately classify their stuff for you. It has failed (for reasons meditating on the previous sentence will make abundantly obvious), and what today seems to be the "Semantic web" is even moreso a repudiation of the original ideas, rather than confirmation.
- encoderer 9y agoMost apps should have two things: 1) A style guide or component library that is used by both design and engineering for any commonly-used component. In some projects this could just be vanilla Bootstrap. 2) An inline style strategy -- there are now several good options to choose from (Styled components, glamorous, etc). A cool idea here that an engineer on my team implemented recently is using a webpack loader to convert our SASS variables into javascript variables so they can be shared with your styled components.
- Raphmedia 9y ago> A cool idea here that an engineer on my team implemented recently is using a webpack loader to convert our SASS variables into javascript variables so they can be shared with your styled components. What I do is set my variables in a YAML file and inject those into both my JS and CSS files at build time.
- dgreensp 9y agoThe arguments don't pertain directly to writing CSS in JS, in my mind. Writing CSS in JS doesn't force you to couple your styles to your components, or reuse code or not reuse code, or be consistent or inconsistent with your styles. If anything, it gives you more options. The appeal of CSS in JS to me is one less language to think in -- one less syntax to worry about and format and lint and forget semicolons in. Also, modules and defining constants. Most web developers seem to use a compile-to-CSS language and a module system these days anyway, rather than vanilla CSS.
- xxxdarrenxxx 9y agoSame. The only thing that intrigues me is that you can make pretty website for the paranoids who run hard script blockers.
- Kiro 9y ago> OOCSS, SMACSS, BEM, ITCSS, and ECSS I've been writing CSS since IE6 and I was a big proponent of BEM for a long time. In the end it didn't cut it and CSS-in-JS is the first time I've actually felt that the CSS problem is solved. To hear "you should be using BEM instead" feels like someone telling me to go back to ES5.
- breeny592 9y agoSome developers at my workplace are very resistant to change ("why learn ES6 when ES5 works fine" is a classic line we used to get). Trying to move onto a module based CSS approach (whether thats CSS modules, CSS-in-JS etc), and literally one of them went "but you can handle that with namespaces, why not just do that". Don't understand why people will willingly do far more work, with more risk, and more prone to error and bugs, than "learn" (using that liberally given how trivial it is to pick up) a modern approach that solves problems for you, so you can get back to making features, rather than dealing with quirks of older approaches.
- lcfcjs2 9y agoDo you guys not use react? CSS in JS is now the standard.
- jakelazaroff 9y agoBest compromise I've found: CSS modules [1] (commonly implemented with Webpack) which have you write a separate CSS file but modularizes it by exporting hashed versions of the classnames for you to use in your components. It's the best of both worlds: you don't have to give up CSS tooling like Sass or postcss, but you gain modularity (which is really the only problem CSS-in-JS solves). [1] https://github.com/css-modules/css-modules https://github.com/css-modules/css-modules
- illamint 9y agoCSS Modules have been revolutionary for us. I agree, it's a great compromise. I don't really see any reason to go to CSS-in-JS from here. It's scaled very well with our team and applications.
- madeofpalk 9y agoThis looks like it was written by someone who hasn't really used a 'CSS in JS' approach. The complaints are actually non existent. Any CSS-in-JS approach is going to have a way to standardize styles across your application. Regardless, I'm not a huge fan of these CSS-in-JS techniques anyway (although I don't mind Styled Components if I have to use it). CSS Modules, to me, is a far better approach and it sits there in the middleground between 'Pure CSS' and 'CSS-in-JS' > OOCSS, SMACSS, BEM, ITCSS, and ECSS. The beauty of CSS Modules is that it basically merges _naming conventions_ like BEM into CSS 'master'. You don't need a convention because the language just sorts it out for you. Imagine arguing against variable scope in any other language with just saying "hey, just manually namespace your variables!"
- michaldudek 9y agoThis! I feel like everyone forgot about CSS Modules, while I think this is the cleanest and nicest solution to all CSS problems and doesn't make you cringe like CSSinJS or styled components and others.
- breeny592 9y agoCSS modules is pretty clean, but disagree that JSS/styled-components are "cringeworthy". They're very powerful, especially when combined with React component props - i.e. let's say when a component has a prop active, that when true we want to change the color on something. A traditional way to handle that would be by toggling some active class, however this creates coupling from the prop to a class, and then the style to that class as well. With styled-components, you can remove one step from that with the classes, one less thing to think about (the developer doesn't need to think what classes are needed with what props, and then what styles apply on those classes).
- dmalik 9y agoGlen Maddern who helped create CSS modules actually went on to help create Styled Components. Here is a talk he did on his reasoning - https://www.youtube.com/watch?v=MT4D_DioYC8 https://www.youtube.com/watch?v=MT4D_DioYC8 IMO - Use the tools/tech that make you happy.
- ttctciyf 9y agoVery readable article. My favourite line: > Please enable JavaScript to view the comments powered by Disqus.
- naraniano 9y agoImage macro memes in 2017 is like putting fingers down my throat.
- drcode 9y agoPlease stop saying "CSS is for appearance, Javascript is for behavior." Not since the 1990s has it been feasible to write a nontrivial app in which javascript doesn't impact the appearance of a web application. The real choice is whether one does 50% of the "graphical stuff" in CSS and the other 50% in javascript... Or, instead, one just does 100% of the "graphical stuff" in javascript (independent of the merits of either approach- It may still make more sense to leverage CSS as much as possible, though I'm a skeptic of that viewpoint as well.)
- k__ 9y agoI even use CSS in JSX, while some people would consider JSX alone madness already, but it feels really nice to write it that way.
- ng12 9y ago> It baffles me then, when CSS in JS advocates argue for essentially the "copy and paste" methodology when it comes to styling. This is incorrect. Even if you're using JS for styles you still follow best abstraction practices -- just instead of importing your colors and mixins from another LESS file you're importing them from another JS file. It's no different then designing a styling framework in pure CSS. What the author is missing here is the biggest single problem with pure CSS -- reusability. Frameworks like React make it incredibly easy to reuse a widget's logic, but what happens when I want to change the styles? JS-in-CSS allows you to do that as part of the widget's API.
- hfourm 9y agoI have highly been enjoying "CSS" in JS with React and things like Radium and AphroditeCSS
- yuchi 9y agoThis article is a little bit flawed and a little click-bait-y also. CSS-in-JS is more or less enforced-CSS-modules + some sugar + a different way to author your styles. Most of the arguments there are against CSS modules, or “isolated styles”.
- breeny592 9y agoAnd it does a poor job in that regard too. - CSS modules promote more re-use if structured correctly - BEM and the like exist to do the literal opposite, to isolate styles to minimise regression and site wide issues at scale. - Visual consistency is enforced in CSS usually through variables to make sure spacing, colours etc. are the same, with a default set of global styles. There is literally no difference in a modular approach - you can easily have global styles to theme, and then isolate and import the more specific rules as needed. This article reads as "I learnt how to do CSS this way so anything new is scary and wrong"
- yuchi 9y ago> This article reads as "I learnt how to do CSS this way so anything new is scary and wrong" Yes. A little bit sad…
- tarikjn 9y ago> If you're new to this space, some of the practices to check out include OOCSS, SMACSS, BEM, ITCSS, and ECSS. These practices sound a bit outdated to be recommended to someone new to the space. Forget any of these and just use CSS Modules, it guarantees you not only namespacing but explicit dependency between your CSS, which most of these conventions -- which require developer effort and compliance -- can't really offer.
- codebeaker 9y agoThere's nothing on caniuse.com about CSS Modules, perhaps you could share a resource? http://caniuse.com/#search=css%20modules http://caniuse.com/#search=css%20modules I don't need any fancy tools or precompilers/processors/etc to use BEM or SMACSS, so I think you may be mistaken about how Css Modules are comparable to the list given.
- tarikjn 9y agoThe idea that a best practice should be usable without a pre-processor has sailed. The fastest people give up on that, the better Web development will be for it.
- adamnemecek 9y ago"As the lead for ZURB Foundation, I've trained hundreds of people on frontend frameworks and best practices." Ok, this kinda explains everything.
- dmitriid 9y agoFunnily enough, it's impossible to properly style many of ZURB's components, as their CSS is tightly coupled with the DOM
- Wintamute 9y agoI don't think this guy gets it. In real life large web apps CSS is very coupled to behaviour and DOM structure. A large part of the advances towards _adaptable_ component-based code comes only when you let go of principles like DRY. Let me put it this way, if I come along to change a feature in one of the 100s or 1000s of components in a project I _only_ want to think about the JS and CSS in that component's folder. I don't want to think about how that component exists in a vast web of generic CSS utilities and abstracted decoupled code. Copy and pasting CSS properties is cheap. Conversely overly abstracting your presentational code is a short cut to expensive CSS spaghetti. It's about component encapsulation, which intimately includes its visual presentation. If you can't think of your component as encapsulated single unit then you might as well not be using components. And if you're not using components, then for the love of God don't use CSS in JS.
- chriswarbo 9y ago> A large part of the advances towards _adaptable_ component-based code comes only when you let go of principles like DRY. > I don't want to think about how that component exists in a vast web of generic CSS utilities and abstracted decoupled code. Copy and pasting CSS properties is cheap. Conversely overly abstracting your presentational code is a short cut to expensive CSS spaghetti. You probably know this, but based on your phrasing I just wanted to point out that DRY isn't for mechanically compressing source code; it's for removing 'out of sync' issues, like causing bugs when we forget to update this copy of a procedure when we altered that copy. Removing such 'conceptual repetition' makes life easier, since (a) we don't need to remember any couplings that need to be kept in sync (this is the "obvious" benefit), but equally importantly (b) if there are multiple copies of something, we don't have to worry about the other ones since they're not related. It's perfectly fine if many similar chunks of code are scattered around a project, as long as they don't have to be 'kept in sync'. The whole point of "components" (/modules/packages/etc.) is to be self-contained, so it's perfectly reasonable to avoid coupling them together in a "vast web". Wrong abstraction < Redundancy < Elegant abstraction
- codedokode 9y agoIn CSS if several components have similar styles it is often better to copy-paste because in future you might need to change those components independently.
- santoriv 9y ago> Keeping things 'DRY' and having reusable code rather than constantly repeating yourself is generally considered a good practice in software development. It enables fixes and changes to occur in one place, rather than having to be replicated a multitude of places throughout a codebase. It baffles me then, when CSS in JS advocates argue for essentially the "copy and paste" methodology when it comes to styling. DRY means different things in different contexts - if you are writing a utility function that is pure and has no side effects, then of course you want to write the function once. The CSS cascade, however, has a tendency to spew side effects all over your application views (e.g. one style that affects a ton of different components), which you then need to override by adding new styles. But be careful, because your new styles have side effects also! Ad infinitum.... For this reason, I regard the CSS cascade as an anti-pattern in most situations. I think that ideally, you want to isolate most of your view specific css to a module attached to the view - so that you are pretty confident that it doesn't have any side effects AND it's easy to know when you can safely delete it. That way you can avoid specificity wars and doing a paranoid but justifiable 'Search in All Files' every time you want to change a style.
- woah 9y agoWhat? It's very easy to be DRY in js by copying properties from style modules into the objects containing the styles of a particular component.
- K0nserv 9y agoThere are concerns with CSS in JS, but the arguments in this blog post are all very weak or non existant. Structural/Behavioral Vs Graphical The introduction of component based tools changes how we design and build our application. No longer is the fact that you can wireframe your whole application valuable instead being able to build individual components and later compose those is valuable. This means that the graphical properties being tightly coupled to a component is actually good. Loose coupling vs tight coupling Component based systems can be built with loosley coupled components, but that doesn't mean the components themselves should loosely coupled to their own implementation. This is more analgous to the native platforms too. Visual Consistency Claiming that CSS in JS produces visual incosistency is about as true as claiming that CSS does the same. In both cases you can be more or less inconsitent based on your chosen implementation method. In both cases you can move the lowest level design tokens[0] to a single places/system. Arguably Javascript being a more expressive programming language is actually better at achieving consistency via the more powerful variable system. Code Reuse Again with a design token system in place changing the design language etc is as easy as changing a few variables. Personally I think the more interesting problems with CSS in JS is the inability to extract the CSS out into css files to be shipped along the application and how that pertains to server side rendering. 0: https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/tokens_intro.htm https://developer.salesforce.com/docs/atlas.en-us.lightning....
- curioussavage 9y agoThe issue with shipping server side CSS is solved in frameworks like styled components too.
- ambewas 9y ago> Rather than being tightly linked to structure, these are very loosely coupled - this is why one can often wireframe an entire application out before styling it! Here's one of the premises on which the article was written - and I must wholeheartedly disagree. If you're looking to write clean, maintainable CSS - you MUST consider DOM-structure of the thing you're styling as well. Too often, quirky CSS selectors are written, only because someone failed to foresee how HTML and CSS work together to create a visual. This decoupling of the HTML that's written, and a CSS "theme" being written/applied after the fact, is also where things like negative margins (ugh) and the like tend to come from. Now, I've been working on a very large component library in React, and keeping our CSS maintainable has not been an issue. We've got one (S)CSS file per component, and it resides in that component folder. And while the file is separate, we absolutely do not allow anyone to develop any component anymore, without having any knowledge of how to style the thing. We used to do exactly that: other devs would develop component, we would try to style them afterwards. This always results in either us writing messy CSS with crazy selectors or - and more often - we simply opted to re-write the entire HTML, to suit our styling needs. At this point in time though, I would love to write some CSS-in-JS here. Too often we need to use variables based on JS logic; And it ends up as an inline style right now, anyway... All in all, if the writer believes HTML and CSS can be written separately, without resulting in a terrible mess, I'm having a lot of difficulty accepting that they know what they're talking about. Sounds like they never had to work on, or maintain, a large application.
- bcarroll22 9y ago> JavaScript used to do this, and we fixed it by encapsulating everything in modules and using tools like webpack to stitch everything together. We've done the same with CSS, and CSS modules work extremely well. For us, they've even eased the need for SCSS.
- enkay 9y agoIn practice, DRY in CSS ends up making code very hard to maintain. It creates ghost side effects where you change something on one page and break something on another page unknowingly. With the exception of a few elements that don't really change at all from one page another like buttons, doing a little bit of copy pasting or search and replace between files is easier. Sure, you might forget to update one page or component here and there, but at least it won't be broken. Better a component is inconsistent in style but functional than broken. Using a few variables for things like color and spacing can also help minimize this problem. Keeping most of my CSS components encapsulated and "namespaced" has worked a lot better in practice than trying to make everything reusable and coupled together in ways that you'll forget about when you have to come back to that project a few months later.
- kingkool68 9y agoCouldn't agree more. I finished some refacotring of a CSS done with the DRY mantra and there were so many hidden gotchas. When I changed one thing it would end up breaking a number of unrelated things.
- beatricep 9y agoSveikinimai jums, Mes (beatricepfam@gmail.com) siūlo ir saugus interneto paslaugos, užtikrintos paskolos palūkanų labai žemu 2%. Mes siūlome asmeninės paskolos, konsolidavimo paskolos skola, rizikos kapitalo, verslo paskolas, studentų paskolas, būsto paskolas arba "pasiruošęs dėl tam tikrų priežasčių, bet!" - Jums bloga kredito? Jūs visada galite klausti. Pastaba: Dėl asmeninės paskolos suma yra mažiausiai 150 000 eur, o daugiausiai 5,000,000 eurų, o bendrovės / investicijų suma yra bent 100 000€ ir 50,000,000€ maksimalus. Susisiekite su mumis šiandien jūsų paraiškų! beatricepfam@gmail.com
- megamindbrian 9y agoI've worked on many different codebases. CSS and script tags add to the mess something awful. For cleaning CSS I take an existing site open with developer console and click through every HTML element in the tree looking for alignments offsets, centering madness before flexbox, font size and color corrections are all stripped away. These settings belong in the top level body or global part of the CSS. I flatten out the HTML and CSS alike so all my elements are at most 4 levels deep. This is a process that takes about 1 day per product page. It's a horrible pain to clean up a site but the payoff is easier maintenance in the future and hopefully some acknowledgement that the page loads better. This skill can easily be trained in to developers. I hope this reminds everyone that computing is a skill that must be practiced. It isn't normal to use tables for layout these days, just like it is no longer normal to use JavaScript for centering elements vertically. This is fixed with flexbox. Please learn and use it!
- jacobr 9y agoTry doing this in a team of 5-500 developers continously adding features all over the site. Then try adding an isolated component in a sidebar somewhere with 0% risk of visual regression elsewhere.
- colek42 9y agoI have started using and evangelizing styled-components in our react projects. Hard to explain, but it just feels like it is the right way to do CSS. Having everything to do with the view for a component in one file works well for the way I work.
- nikolay 9y agoVery well-put! In trying to solve one problem, we create tons more. So much more added complexity! The React stack is growing out of control with the flavor of the day changing daily per se!
- swyx 9y agoAre we dumbing CSS-in-JS down just to attack it? CSS-in-JS doesnt mean you have to sacrifice visual consistency or DRY principles. you can still create a central system of CSS properties and import them to be used while being explicit and scoped about the stuff that is not shared. I feel like this is being debated more than its worth. As with everything, pick the right tool for the job.
- mmmeff 9y agoamen
- DonHopkins 9y agoWhy can't people just not go out of their way to write crap CSS in the first place? There seems to be this trend to show off all the possible different ways you know of addressing a single element somewhere, by pointlessly combining them together in brittle ways that depend on each other and accidental document structure, using haphazard random inconsistent naming conventions. If there's only one of them, then use a fucking id.
- Cozumel 9y ago^this. If people took the time to learn the basics then this whole thing wouldn't even be an issue.
- breeny592 9y agoContext: I work on a large CMS powered site We have a company wide rule of no IDs in styles - we actually lint for them. As a front end team, we can't be certain that there will only ever be one of a component on a page at a time. Sometimes we can be mostly certain, but the content authors can theoretically do anything, and our job is to provide them flexibility whilst keeping the site looking good. Modular CSS would be a God send for us, would be able to handle a lot of things much cleaner but sadly the current build of the CMS doesn't allow for it. In small sites, or anything with static content, IDs are more than valid. But it becomes a lot harder when dynamic content, especially dynamic components, come into play.
- curioussavage 9y agoI think the best answer to this is three questions. Is the browser being used to make dynamic "apps" instead of static web pages? How do app frameworks/toolkits on other platforms style their apps? And finally: Do you think the people who designed all of those frameworks were stupid? Seems to me like the web is finally catching up with the only sane way of styling the widgets in an app. It's done in the same language and it's per component/ widget.
- devsmt 9y agonot all CSS is equal: if you define global styles like h1{color:#000;} you want them outside components, in components you want the minimum of css needed to render correctly your date picker or whatever you are trying to accomplish and you want minimize external dependency on the global css.
- nkkollaw 9y agoWhat's wrong with web components? They solve the problem very elegantly, and thanks to Polymer and others we can use them today.
- adamsea 9y agoMost of the author's concerns about reusability, maintainability, and separation of concerns can be addressed by thoughtfully structuring your JavaScript application project. For example, using React/Redux and JSS, the JSS (a CSS-in-JS technology which uses CSS modules among other things) goes in the "dumb" component files, not the "smart" (or "linked") container components which pass Redux state and various functions to the "dumb" component. And then creating a styles.js file (or multiple files if appropriate) is a simple way to create shared JSS styles which can then be imported into various component files as needed.
- lilactown 9y agoEvery time "separation of concerns" and HTML, CSS and JS come up, I want to scream. I don't think I've ever seen so many people have such a shallow understanding of what a term means. It's practically a trigger at this point. Everyone who is confused: HTML, CSS and JS are not concerns. They do not represent an intelligent way of separating your application code. Every time you write the ID of an HTML tag, or a component- or feature-specific class name, you are violating "separation of concerns."
- seanwilson 9y agoI think the phrase "thought terminating cliche" is a good summary of this concept... I always hear things like separating everything out that way can make it easier for non-technical people to edit the HTML which is rarely going to be a practical idea. > Every time you write the ID of an HTML tag, or a component- or feature-specific class name, you are violating "separation of concerns." Yes, you can separate out a lot of the behaviour and presentation between HTML, CSS and JS but there's always some overlap you just can't get away from. Frequently you want to change the structure of the HTML just to make the styling easier for example because there isn't a practical alternative. Jumping around between files to edit the HTML, add a class, styling the class in CSS, modifying the HTML to help with the styling and then adding click behaviour in JavaScript, then trying to figure how it all works again later involves a lot of context switching.
- dmitriid 9y ago> The Real Answer: Better CSS Practices... > If you're new to this space, some of the practices to check out include OOCSS, SMACSS, BEM, ITCSS, and ECSS This is not a real answer. It's an attempt to fix the broken screwdriver with ducktape, bird poo, and spit.
- nathan_f77 9y agoI've been trying out CSS modules in my new project. I've also set up a library that generates Flow type definitions, so I get static type checking and autocomplete for my CSS classes [1]. It's pretty awesome, and works with SASS too. I love having every React component self-contained. It makes refactoring and reusing code so much easier. [1] https://hackernoon.com/type-safe-css-modules-with-flow-dd95e761bbe5 https://hackernoon.com/type-safe-css-modules-with-flow-dd95e...
- AJStacy 9y agoThe Shadow DOM solves all of CSS's scoping problems.
- tomelders 9y agoCSS is for a print paradigm. But it makes very little sense in a web app paradigm. So in lieu of anything better, we encapsulate CSS with hashes, and write it in Javascript so we can have dynamic styling. What we really need is a better way to style web apps.
- deleted 9y ago[deleted]
- xXinVeRteDx 9y agoLESS/SASS takes care of this with nesting (ie. scoping css rules).
- thinbeige 9y ago'Broken screwdriver?' Don't get OP's analogy. Does he mean CSS? While CSS can sometimes be nerve-racking it's the most modern layouting system. There was a reason that the React Native team chose CSS' Flexbox for their layouting system.
- JoshMnem 9y agoElm CSS looks interesting: https://www.youtube.com/watch?v=W4Xnas3exk0 https://www.youtube.com/watch?v=W4Xnas3exk0
- err4nt 9y agoI agree that often times CSS-in-JS forfeits some of the expressive power that makes CSS powerful, in the attempt to gain some muscle from JavaScript. Instead of CSS-in-JS I think a better pattern for extending CSS with JavaScript is 'event-driven virtual stylesheets', which I call JS-in-CSS. I'm writing a website dedicated to JS-in-CSS techniques, plugins, and theory. It's still a heavy WIP right now, but there are ~20 plugins that can be used and code samples and links to their documentation which is good to go already: http://responsive.style/ http://responsive.style/ I'm trying to write down and share the results of what I've found trying to combine JavaScript styling with CSS for years, and the patterns and techniques that make the two useful. You should be able to take full advantage of 100% of CSS's expressive power _and_ still augment it with JavaScript logic. You can have the best of both, and this JS-in-CSS pattern works in every browser you can imagine (I recently got it working in IE7 and IE6 just for fun!(
- enturn 9y agoLike religion there's no one true way but I hope people agree that using analogies in technical discussions adds to confusion and is best avoided.
- azr79 9y agoTell that to ReactJS devs, those mad men include even HTML in their JS files, how insane do you have to be.
- megamindbrian 9y agoHEY LOOK, NO ONE CARES ABOUT YOUR PROBLEMS! http://caniuse.com/#feat=style-scoped http://caniuse.com/#feat=style-scoped