4 ms·
Disclaimer: we have been using functional css for about 2 years. Let's review the main use case you present "I want to tweak all buttons on the site, I tweak i
by batmansmk 8y ago
Disclaimer: we have been using functional css for about 2 years.
Let's review the main use case you present "I want to tweak all buttons on the site, I tweak it in one place":
- How many times do I have to change all the buttons on my app?
- Does changing one class work to change all buttons in practice? Don't I end up having the color overloaded 3 times, cascading over and leaking in 5 others spots?
- Are most of my edits in CSS tweaking existing rules, or piling up more CSS? Usually, in a large codebase, I end up just adding a class instead of tweaking one and figuring out if I broke anything anywhere.
- If I use a component-based approach, like Angular or React, do I really have to change classes everywhere with functional css, or just in the button component?
- Is styling "functional"? Can I always change the styling of a class without changing its semantics - like if I put the primary button the same as the secondary, did the naming help?
Your case may be different and our point of view may also evolve.
With functional CSS + component-based approach, I rarely have to use the style inspector - and produce beautiful, maintainable app with 14KB of CSS and no styling bug.
All my other attempts using CSS "the right way" lead me to 1MB+ of CSS.
The benefits of CSS to factor style by function seems very infrequent compared to the problems they introduce.
- Retric 8y ago> Usually, in a large codebase, I end up just adding a class instead of tweaking one and figuring out if I broke anything anywhere. It's very easy to just make another CSS class everywhere, but that defeats the point of CSS and you might as well just use inline styles. Clean well maintained CSS makes a huge difference. The problem is your CSS needs to map to semantic meaning of what's going on, and you need to maintain the effort to keep it clean. > How many times do I have to change all the buttons on my app? How about how often do you need to change all your 'submit' buttons? The HTML element type is again vastly less important than what each element means.
- ashelmire 8y ago> - How many times do I have to change all the buttons on my app? When making a styling change like this, it's typical to change it app-wide. > - Does changing one class work to change all buttons in practice? Don't I end up having the color overloaded 3 times, cascading over and leaking in 5 others spots? I can change the border-radius on all of my buttons, and they will all change, and still have their color-specific classes. > - Are most of my edits in CSS tweaking existing rules, or piling up more CSS? Usually, in a large codebase, I end up just adding a class instead of tweaking one and figuring out if I broke anything anywhere. This is unfortunately quite common in practice - because maintenance is hard and practices are bad. But it is definitely possible to have robust, reusable css. > - If I use a component-based approach, like Angular or React, do I really have to change classes everywhere with functional css, or just in the button component? Phew! A component just for a button. What a twist! I don't think most people are making components for each html element. In fact, I'd say this is pretty redundant and overengineering things in a bad way. Guess what - html has these nifty components called buttons too, and you can also style them. Wouldn't any minor change to your button component require then passing in props (just like classes)? <Button propName={"danger"}><button></button></Button> doesn't really seem better than <button class="btn--danger"></button> to me. > - Is styling "functional"? Can I always change the styling of a class without changing its semantics - like if I put the primary button the same as the secondary, did the naming help? Not really sure what you're getting at here.
- Izkata 8y ago> Phew! A component just for a button. What a twist! I don't think most people are making components for each html element. In fact, I'd say this is pretty redundant and overengineering things in a bad way. Welcome to the world of web components. This is actually really common, especially in React with css modules - this way you can use your custom button without even having to think about the CSS (or any extra complexity like tooltips and accessibility), even from a common library used across projects.
- rhizome 8y agoI want to call this "transverse encapsulation."
- RussianCow 8y ago> Phew! A component just for a button. What a twist! I don't think most people are making components for each html element. In fact, I'd say this is pretty redundant and overengineering things in a bad way. Guess what - html has these nifty components called buttons too, and you can also style them. Wouldn't any minor change to your button component require then passing in props (just like classes)? <Button propName={"danger"}><button></button></Button> doesn't really seem better than <button class="btn--danger"></button> to me. We use custom components like this at work, and it actually works quite nicely because you get to see all the different "types" of buttons at a glance by looking at the prop types. Using the component looks something like this: <Button label="Click me!" primary /> I've found that it's helpful for enforcing consistency, so that you have to go out of your way to apply custom styles to a button (which isn't required 95% of the time). Plus, it helps abstract things that don't have anything to do with the <button> HTML element but are often tied together, like being able to automatically make a button a link without having to wrap it in an <a> tag: <Button label="Home" href="/" /> It's all minor stuff, but it enforces consistency and keeps you from having to think about CSS classes at all most of the time.
- antjanus 8y agoHey! I'm using basically a Bootstrap-like syntax for my own "framework" at work. We've been running it for almost 4 years so I'd love to respond to everything your saying: 1. it does actually happen but more often than not, individual buttons need some changes. 2. absolutely but that's why we use SCSS to help "cascade" those changes. Unfortunately, those large changes, again, require individual tweaks in some tricky areas. 3. adding classes is always the safer approach. One thing that has helped us is to make sure classes hold little (but valuable!) responsibility. 4. this is an awesome question. So, for us, those little adjustments specified in the post (small margins and so on) were tweaked at component-CSS level while large-changes were kept to our SCSS framework 5. It's basically CSS-in-HTML So my own experience has taught me a general approach of my own: 1. create a framework for your site in SCSS. This includes basic styles for buttons, input boxes, colors, typography, tables etc. but stay away from more complicated styles (like trying to create CSS for a "profile card") 2. keep "component" CSS inside a component. Profile card CSS goes in profile.component.scss 3. overrides/hacks belong to where those overrides/hacks need to happen.
- darth_mastah 8y agoI've been working with the front end for over a decade now in small and big teams, with different approach to CSS. I've seen things go horribly wrong for all the seemingly good reasons. Bloated CSS, people fearing to make any changes to existing "semantic" classes, people making changes to existing classes and introducing unforeseeable bugs in remote parts of the application, you name it. In my view nothing beats functional CSS. It's simple, pragmatic, easy to read and understand. And most importantly it'd hard to introduce hidden bugs with this approach.
- deleted 8y ago[deleted]