Hacker News new | past | comments | ask | show | jobs | submit login

In my work doing frontend web development CSS is the primary language I use. I don't use Less or SASS, I just write straightforward CSS.

The only limitation I've run up against as far as responsive styling goes was that @media queries were always scoped to the browser's width/height, and I figured I could build much more advanced layouts if I had a way of scoping styles to individual elements. It turns out that's true, I have a plugin that lets me do this, so between regular CSS and these extra 'element queries' I have no issue styling anything I want. My plugin works down including IE8, so there's nowhere I need to write CSS where I can't use it.

I'm not aware of how/why CSS needs to be fixed or replaced, it's a great solution for what it does.

What do you propose instead of CSS? When you have well written HTML, it takes surprisingly few CSS declarations to add a good style!




Most of the time when I see people complain about CSS it's because either they don't know how CSS works, or they want it to do something it wasn't designed to do in the first place.

Most of the time it's because they don't know how it works.


Lack of ability to nest rules in CSS makes it harder to organize styles. Not being able to create mixins and such makes all too easy to have to copy-paste and memorize cross-browser solutions & vendor specific rules for certain browsers.

In short, there is a lot of inefficiency with the current system that preprocessors help alleviate.


They truthfully do help alleviate such things, but none of this is impossible nor too terribly difficult to handle with plain old CSS.

Oddly enough, I've seen a number of people recently complaining about nesting in SASS claiming it creates problems. You just can't make everybody happy.


Simply indent child rules one step to the right. This even allow you to use code folding to easily see what goes with what.

Minify the code before it goes into production and you are ready to go.


Why do you need to nest things? The 'C' in CSS stands for 'cascading'.

Don't fear the cascade!


Well, it does clean up the code a bit, depending on your point of view. But it wouldn't necessarily interfere with cascade.

It's just right now, because CSS doesn't support it, that SASS code gets compiled into large selectors if you aren't careful.


It helps a little in the code organization, however, it creates new problems.

It makes deep nested code hard or impossible to reuse. It tightly couples style and markup, so a change in the latter can break the former, etc.

So while it is a nice feature to have, I'd recommend using it scarcely and with great care.


That's not a problem, that's not understanding how it works.

Any nested SCSS is impossible to reuse outside of its parent scope. If someone is using nested SCSS and expecting to reuse that code elsewhere then they are doing it wrong. It's the same problem that exists if one were to create a class as a child of an ID and then expect to use that class outside of the ID's scope.


Who needs code organization when Inspect Element gives you the filename and line-number, and all editors have Control-F :)

You can edit minified code if you've had enough coffee!


If you frequently see people not knowing how CSS works, then that could be a sign that CSS is fundamentally broken, over engineered, etc for what it does...

(rather than those devs being "stupid", "ignorant", "incompetent" etc).


Curious question from one frontend dev to another. Why don't you use Less or SASS? If server side compilation / javascript mode are a problem, you can simply set up a watch locally on your files using grunt or gulp.


I think there's a short list of situations where using a higher level language to describe CSS makes sense:

- when demonstrating a pattern present in CSS at a higher level, to educate people who write CSS

- when dealing with CSS animations where different browsers also use different properties

- when it's your job to output lots of different pieces of CSS based off the same pattern

Most of the time I'm either building new websites from scratch, or retrofitting old existing websites with responsive CSS and fixing problems. The web is written in three languages and only three languages: HTML, CSS, and JavaScript. If you're not writing one of those, you aren't writing the web. I can never be sure of the stack of the projects I'm going to be asked to fix, so if my requirement is: "Well I can fix it, but only as long as you use SASS" I'm going to be very hungry in life.

I can (and do write) CSS from my phone, tablet, and multiple computers - but if I had a SASS/Less workflow, that would severely limit the situations where I could write new code. Frontend web shouldn't need to be compiled!

Also, unless/until things like colour variables can also be used from JavaScript, I don't how useful CSS-only variables can really be.

In my experience, specializing specifically in responsive CSS - I've just never run into a situation where I needed or could make use of the features of SASS or Less (or Stylus, or others) where it didn't create more work for me, plus introduce technical debt into my projects, while simultaneously restricting which devices I could work from and on which sites I could work.

I could work that way, but I feel like I'd get 'Less' work done compared to the flexibility of pure CSS.

Frontend to frontend dev: what is it you reach for in SASS or Less that can't be done by CSS, JavaScript, and HTML?


- Importing modules with zero performance impact. - Variables! Think how they help you in other languages. $primary is much more readable than some random hex code. - Functions! darken($primary, 10%), again much more readable than hex codes. - Helps avoiding duplication through several means, like mixins, loops and so on. - Forever forgetting vendor prefixes and effortlessly keeping up to date. - Creating sprites or base64 images automatically, never having to "craft" those by hand ever again.

The list goes on and on. And the best thing, SCSS and Less are CSS backwards compatible, so you can choose whatever features you want and pretend you're writing just CSS.

I was super anti-preprocessors for pretty much the same reasons you are. But the one day I tried them out and never looked back.

Ignore gulp, grunt, webpack and whatever people tell you to use. Start super easy, with just the "compiler", and once something annoys you, look for a solution.

Also pick up the features you want. I started using only variables and ignored the rest, and added more tricks to my repertoire as needed.


I understand where you stand from, I've done quite a lot of work on support / upgrades of existing websites. I still think you may benefit from a workflow that uses a local build system... and once you use a build system, why not throw a preprocessor in?

I can give you an exemple of my workflow for simple websites using Gulp.js (I used to use grunt.js, but really, it's all the same)

I have a frontend folder structure that I carry around projects. There's a components folder and a build folder. The build folder is for minified files only.

The components folder is split between components of the website, a bundle folder and a common folder. So I have /frontend/bundles, /frontend/common and let's say, /frontend/core-navigation.

Under frontend/core-navigation, I have /styles (and scripts but let's ignore scripts for now). Under /styles, I have a main-menu.scss file. This allow me to have in there only the styles of the menu of the website. However, I don't want to burden this stylesheet with font-sizes, browser hacks, media queries definitions, etc.

That's where the /frontend/common/styles folder come into play. In this folder, I have a config.scss file. This is where the preprocessor really shines. All the reusable and common variables, styles and mixins are there.

Let's say $brand-color: #b41e3c; which is a blood red. Then, I have all the colors that starts from this color. The color for the titles of my website has to be the brand color but a bit lighter. That would be $light-title-color: adjust-hue(desaturate(lighten($brand-color, 20.58824%), .47553%), -4.28571deg);. Repeat for every color.

Then, I have my font variables, $text-font: 'pier sans', sans-serif; $light-weight: 300; $extrabold-weight: 800; $letter-spacing-normal: .05em;

I also have a bunch of mixins that are going to be used all over the website. @mixin icon-bag-white {@include scalable-icon-mixin('icon_bag.svg', 'common', $color: $white);} %hover-transition {transition: all #{$konstan-transition-hover}ms ease-out, z-index 1ms;} %form-label { display: inline-block; font-size: rem-calc(11); text-transform: uppercase; &.required em, .required { float: right; color: $brand-palette; } } etc.

My media queries are also all predefined. $xlarge-up: "#{$screen} and (min-width:#{lower-bound($xlarge-range)})"; which allow me to easily use mediaqueries this way: @media #{$xlarge-up} { /styles for xlarge-up/}

Back to frontend/core-navigation/main-menu.scss. Now that I have all those variables, I can easily style my main menu using the existing variables and styles definition that are in my config file. If I want to have a form label, I can simply @extend %form-label and I don't have to rewrite all those style definitions. I work in team with other developers, so it really help to have those definitions written only once so that we don't end up with code duplication.

All of those styles sheets are bundles under the /frontend/bundles folder. In this folder, I have multiple files filled with @import definitions. All those are bundles and using Gulp.js, I can output them wherever I want. Most of the time that's going to be under /frontend/build/stylescore.css. However, if I'm working on a CMS website, I can output the minified stylesheet in let's say, /magento/skin/styles.

I use gulp.js to minify my stylesheets, to compress my images, to generate multiple versions of my share icon for every device out there, etc.

Something really cool too is a task which write browser prefix and browser hacks for me. I simply write display: flex; and when I save the file, it's going to put display: -webkit-box; display: -webkit-flex; display: -ms-flexbox; display: flex; in the build file for me. There's one for polyfills too, so you can use rounded corners on IE7, etc.

All of my files are put under a watch task, so whenever I save a file, the workflow starts by itself. If make changes to main-menu.scss and save it, it's automatically going to minify the file and send it in the right folder. I can work as if my .scss file is a normal .css file. And the beauty of it? It's all done locally, no dependancy on a server or a backend guy. I don't need to install any php module on the server or anything. I simply throw the /build file on the production server and everything is going to work the way I want it to.

I have a similar workflow that use the same folder structure for my scripts.


That's a pretty elaborate setup.

I have my own toolbox of scripts and plugins, but they're all written in CSS, HTML, and JS. I have CSS files like http://staticresource.com/basic.css upon which I can layer other colour styles like: http://staticresource.com/template/css/themes/swiss.css

I also have plugins that I've written like http://staticresource.com/notifications.html

But this year I decided to do something crazy and put them all together in a really simple site layout: http://staticresource.com/template (source https://github.com/tomhodgins/template-factory)

In the Template Factory you can test all of the themes and the plugins, and add theme support so they work together.

For me to define a new 'brand' on top of this would just mean to author one more CSS stylesheet on top of basic.css and the various plugins used.

Still, if I've gotten this far without Less or Sass - where should I add them where it would benefit me?

I find I do end up hacking on iPad a lot, I can just write HTML, CSS, and JS and create things, then move it to a computer for further work. Here's a super simple HTML utility I made last week to help me build mailto URLS: http://staticresource.com/mailto.html It uses basic.css and the notifcations plugin, but check out the source. You could write a little HTML page like that anywhere, on any device.

For me to introduce some kind of a build process with all these different moving parts would severely restrict the situations when and where I can get work done! I'm a freelancer, I don't get paid by the hour, I get paid for the amount of value I can provide, so it's always in my be$t intere$t to break down any barrier that stops me from being able to work.

I'm able to do a surprising amount of work from mobile, despite mobile browsers lacking a lot of development features desktop browser make available. I have a little app that lets me test responsively on mobile: http://staticresource.com/speedtest.html and another that lets me view the source of any site on: http://staticresource.com/inspect/?

So for me to abandon this freedom and flexibility to only be able to work from one machine, with all these processes running and up to date sounds like a massive step back in productivity for me.

It does sound like you have a beautifully amazing system set up, but it feels full of potential points of failure that don't need to exist. If you need to update one line of text on a website, you should be able to open up a text file on any device, edit one line, and save. Having to do anything else to get something updated seems like intentionally going out of your way to create work for yourself, no?

Also, doing a lot of responsive stuff I've been turned off the idea of using pre-defined breakpoints for responsive design. Your @media (or other) queries need to respond to the elements in your layout and when you feel they need to adapt, which means those breakpoints are defined more by the design than the device. I use a solution that lets me scope responsive styles to the elements themselves, which is an even better solution for high precision responsiveness! Check out http://elementqueries.com It doesn't work so well with SASS, but here's an example of something I built with it recently: http://staticresource.com/reports.html

This design isn't responsive, it's designed to be printed 8.5x11 actually, but you'll notice in my code I have defined color variables in JavaScript and used them both in the JavaScript I send off to Google Charts, as well as in my styles. You wouldn't be able to do that with SASS/Less variables, but this is a real-world use case where I thought using variables might be better than not using them :)


I like all those tools, plugins, etc. you have going. They are great.

As for the build system that I use, I can update it via the command line and I can also install it on any machine via npm install. I do agree that with this, I couldn't work on an iPad, but I have that 11inch macbook air for that job already.

Here's the open sourced version that is the base of my workflow (this one is the one we use where I work, my own is a bit simpler but based on the same concepts). Take a look: https://github.com/absolunet/nwayo/tree/master/src

As for the breakpoints, I use the variables as a starting point (small mobile, large mobile, tablet, desktop, big desktop, etc.) but do end up using hardcoded breakpoints for small components or in betweens.

edit: Mail me if you want to chat more, contact info in profile!




Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | Legal | Apply to YC | Contact

Search: