News for hackers. Stuff that matters.
Re:Why I don’t use CSS preprocessors by PaulB_GD on Saturday April 02, 2016 @01:27AM (#11410368)
Variables though, I can't see how you can go without them. Being able to change 6 characters and have the entire site theme change for a client is great.
Re:Why I don’t use CSS preprocessors by BinaryIdiot on Saturday April 02, 2016 @04:52AM (#11410795)
> Variables though, I can't see how you can go without them.

The point of variables is to allow the setting of one style property and applying it to others, right? So why not just to that at the top level element and inherit it down? Typically you only want to select a handful of colors for a web site / application so simply set those at the highest level possible then allow CSS inheritance to work.

Out of all of the big projects I've been on only one has used CSS preprocessors and I've never run into an issue with needing to change a value in too many places. It doesn't seem all that hard to avoid if I'm being honest here it just really, really depends on the structure of your CSS and HTML.

Re:Why I don’t use CSS preprocessors by agnivade on Saturday April 02, 2016 @05:04AM (#11410827)
I am no expert in css but let's say you have a title heading color and you want the button color to be the same as that. You need to specify it separately in 2 places right ?
Re:Why I don’t use CSS preprocessors by BinaryIdiot on Saturday April 02, 2016 @05:13AM (#11410847)
No but ultimately specifying it in two places could be better.

So first off if you want it to literally be the same then you could do something like:

  h1, button {
    color: #343434;
  }
That would make them the same. You could also do

  .primaryColor {
    color: #343434;
  }
Then set the elements which should have a primary color with that class.

But if you could break my first example apart and set it in two places just as easily. But that's setting it at a high level element itself. You could even go crazier and set EVERYTHING to that color but ultimately many of these decisions have to be context based to decide.

Re:Why I don’t use CSS preprocessors by sangnoir on Saturday April 02, 2016 @05:40AM (#11410902)
What if want to use the primary color as the background-color to a nav element and as the border-color to inputs and textareas as well? If the designer changes to a different shade, do you do a global search-and-replace?

The way I see it, CSS preprocessors allow for code reuse via composition - vanilla CSS restricts you to inheritance.

Re:Why I don’t use CSS preprocessors by tonyhb on Saturday April 02, 2016 @06:04AM (#11410952)
Css is quite frankly bullshit (ie. fickle), but I'm proud of it.

The actual art of making visuals usable within a screen is pretty hard to make a language out of. With postcss and react css modules there are advancements. And still, it's one of the things that I have to put the least amount of effort in for the most amount of gain.

Re:Why I don’t use CSS preprocessors by BinaryIdiot on Saturday April 02, 2016 @12:44PM (#11412162)
> What if want to use the primary color as the background-color to a nav element and as the border-color to inputs and textareas as well? If the designer changes to a different shade, do you do a global search-and-replace?

I already explained this? You set it at the top level. Have a set of top level HTML elements / classes that set all of these defaults. Then everything inherits from those. Only one place to change them.

Re:Why I don’t use CSS preprocessors by sangnoir on Saturday April 02, 2016 @06:36PM (#11413866)
> I already explained this? You set it at the top level

Not quite: 'color', 'background-color' and 'border-color' are 3 separate properties that can't be be inherited from one place using vanilla CSS

Re:Why I don’t use CSS preprocessors by BinaryIdiot on Sunday April 03, 2016 @07:09PM (#11418270)
Those are three different ways of coloring something (and very rarely are exactly the same in my experience). Using variables to make those three the same color is an abuse of DRY in my opinion.
Re:Why I don’t use CSS preprocessors by sangnoir on Monday April 04, 2016 @12:19PM (#11423077)
> Using variables to make those three the same color is an abuse of DRY in my opinion.

I disagree - as a matter of fact, a lot of CSS frameworks have the concept of a "primary color" that is used in the manner I have described. Additionally,following your idea of DRY would render CSS variables pointless in CSS preprocessors as mixins cover that use-case (setting the same property).

Re:Why I don’t use CSS preprocessors by snarfy on Saturday April 02, 2016 @08:59AM (#11411354)
> Then set the elements which should have a primary color with that class.

But now your markup is littered with styling classes, and you could end up with a .secondary button with a .primaryColor class.

In vanilla css, the only way to really define something like a primary color just once and have it apply correctly to all elements is to define it at a high level in a deeply nested cascade. This of course all breaks as soon as you add a container element and have to go back and add another level of nesting to your css.

Variables in css should be standard.

Re:Why I don’t use CSS preprocessors by bphogan on Saturday April 02, 2016 @12:00PM (#11411977)
Just a nitpick.

I hate, hate, hate having to alter my HTML to apply styles. The idea of

<h1 class="primaryColor">

totally creeps me out. I do it because other people refuse to use preprocessors and think that altering the HTML to include presentational details is fine (see Bootstrap.)

But it still feels gross to me.

Re:Why I don’t use CSS preprocessors by BinaryIdiot on Saturday April 02, 2016 @12:43PM (#11412158)
> totally creeps me out. I do it because other people refuse to use preprocessors and think that altering the HTML to include presentational details is fine (see Bootstrap.) But it still feels gross to me.

To be fair HTML is the presentation. I can understand not wanting to mix business logic from JavaScript into a page but CSS is just the other half of HTML.

If it makes it nicer you could use more generic class terms (such as page information or HTML structure location, etc).

Re:Why I don’t use CSS preprocessors by bphogan on Saturday April 02, 2016 @01:25PM (#11412334)
HTML is not the presentation.

HTML is the content and description of content. You put a <strong> tag around text to make it strong emphasis.

CSS is the presentation. Your browser sees the <strong> tag and applies its default style of making it bold.

Re:Why I don’t use CSS preprocessors by BinaryIdiot on Sunday April 03, 2016 @07:12PM (#11418276)
They're both the presentation. Showing emphasis and structuring content is as much part of the presentation as CSS, maybe even more so if you care about backwards compatibility and graceful degradation.

This is just incredibly pedantic. For all practical purposes HTML + CSS is the presentation. Toss JavaScript into that if you want. Front-end work is the presentation.

Re:Why I don’t use CSS preprocessors by bphogan on Sunday April 10, 2016 @09:46AM (#11466059)
It's not pedantic. It's the way it was designed. Just because people use tables for layout doesn't mean they were intended for that.

As far as graceful degradation, If I open a properly built page in a text-only browser, there are no styles. There's no real emphasis or bolding. There's just text. Because CSS didn't exist.

Now, if you want to live in the early part of the decade when it was OK to put inline styles and background colors in your HTML, that's fine. But the world evolved beyond that. HTML with <body bgcolor" is deprecated.

Because HTML is the content. CSS is how it looks. And JS is how it works.

Re:Why I don’t use CSS preprocessors by myblake on Saturday April 02, 2016 @03:45AM (#11410664)
Yeah this is the one that I don't understand, his argument about wet css being more readable doesn't even make sense in the case of "#ec3f5d" vs "$red", let alone the fact that in a big project not having one place to change this can be a nightmare.
Re:Why I don’t use CSS preprocessors by SixSigma on Saturday April 02, 2016 @06:05AM (#11410955)
how about when $red = #FFFFFF
Re:Why I don’t use CSS preprocessors by iamben on Saturday April 02, 2016 @06:40AM (#11411027)
You're arguing for the sake of it- it was just a bad example. If $red was $leadcolor or something similar, you can define it at the top, comment it to explain what it is, then change it across the whole site in 10 seconds (including the borders which are defined as variables 5% darker and lighter) when the client says "I like it, but the red needs to 'pop' more, do you know what I mean?"
Re:Why I don’t use CSS preprocessors by SixSigma on Saturday April 02, 2016 @08:45AM (#11411320)
I'm not, I have seen code like this where a variable is named after its value when created and then colours swapped out later.
Re:Why I don’t use CSS preprocessors by jjnoakes on Saturday April 02, 2016 @09:49AM (#11411498)
So you are arguing against variables in any programming language.

    int one = 2;
Re:Why I don’t use CSS preprocessors by Silhouette on Saturday April 02, 2016 @10:24AM (#11411619)
You can write bad code in any language, as the saying goes.

However, I've seen projects with a few CSS variables defining the base colours for their scheme and perhaps some tints and shades, and then a second layer of variables defined in terms of the base ones but with more role-based names like heading text colours and focused primary button backgrounds and so on. It's a simple, practical model that has proved very easy to work with and in some cases has stood the test of time for quite a few years now.

Re:Why I don’t use CSS preprocessors by j4kp07 on Saturday April 02, 2016 @04:06AM (#11410704)
I would never allow a design get that far into the process and then allow a client to start testing various colors. That is just asking for trouble.
Re:Why I don’t use CSS preprocessors by Silhouette on Saturday April 02, 2016 @10:16AM (#11411586)
Have you never implemented a design yourself, and then found that when you looked at the results as a whole, it didn't work quite as well as you hoped from the original concept work?

Have you never A/B tested a site and found that varying colours made a difference?

Have you never developed a site with some colour scheme and later found you needed to extend the colour scheme, perhaps to incorporate a new product or service being added to the available range?

Having a colour scheme that is set in stone early on sounds like one of those idealised things that sometimes just doesn't work in the face of reality.

Re:Why I don’t use CSS preprocessors by anotheryou on Saturday April 02, 2016 @12:15PM (#11412053)
I agree!

I'm currently building something that has mild themes for fonts, colors and some margins (and is build on top of a SCSS framework, but that wasn't my choice), without color variables it would be a pain...

Re:Why I don’t use CSS preprocessors by iamben on Saturday April 02, 2016 @06:42AM (#11411031)
But we've all been in a situation where it's got 'that far' and someone more senior has got involved and done exactly that. Plus, it makes designing in the browser waaaay easier.
Re:Why I don’t use CSS preprocessors by ino on Saturday April 02, 2016 @02:41AM (#11410523)
Is there a css3 variables compiler/processor/translator to plain css without variables?

It can be a copy-paste tool on the internet or whatever, no preprocessor or build tools required. You work directly with styles.css3 in the browser and when you're done you transform it to old style without variables, so it works in older browsers.

That's what I wanted to do last week but as I couldn't find such a tool, at the end I did a search/replace. It was a small project obviously.

Re:Why I don’t use CSS preprocessors by jack_jennings on Saturday April 02, 2016 @03:09AM (#11410577)
This might be what you're looking for: https://github.com/segmentio/myth
Re:Why I don’t use CSS preprocessors by ino on Saturday April 02, 2016 @05:01AM (#11410821)
Thanks, this looks good!
Re:Why I don’t use CSS preprocessors by cobalt on Saturday April 02, 2016 @02:56AM (#11410549)
i think that is what postcss does
Re:Why I don’t use CSS preprocessors by floatboth on Saturday April 02, 2016 @10:05AM (#11411547)
PostCSS parses CSS, runs plugins and outputs CSS. Yep, of course there is a plugin that does variables! And the "Myth" tool, mentioned in a comment here, is just a pack of PostCSS plugins.

And the OP uses PostCSS. Apparently, a lot of people here didn't read that part...

Re:Why I don’t use CSS preprocessors by nostrademons on Saturday April 02, 2016 @01:46AM (#11410415)
Sure, but there are plenty of other ways to achieve the same effect. One I used for many years was to run your CSS through the same templating engine that generates your HTML. Wait a few more months and you might also get native CSS vars:

http://caniuse.com/#feat=css-variables

Re:Why I don’t use CSS preprocessors by Lazare on Saturday April 02, 2016 @01:52AM (#11410431)
> One I used for many years was to run your CSS through the same templating engine

So...a preprocessor? :)

Re:Why I don’t use CSS preprocessors by nostrademons on Saturday April 02, 2016 @01:57AM (#11410440)
That you have to use anyway.