You can try to reduce the horribleness of a CSS file, but the language simply doesn't provide the tools needed to do the one thing all programmers need to manage complexity: abstract away the common part of two specific processes into a reusable component.
I'll never forgive the designers of CSS for not at least providing immutable constants, if not variables.
The more I think about it, the more certain I become that immutable constants (a good idea, IMO) are the furthest CSS could safely go down the rabbit hole before the entire enterprise would consume itself in spaghetti-code madness.
Not that plenty about CSS doesn't beg for better abstractions, but turning it into a programming language is kind of a terrifying prospect. I've see too much of what enthusiastic amateurs can inflict with JavaScript.
So what if CSS doesn't have variables? We can add them. CSS is the format it has to reach the browser in, it's not the format we have to write in though. There are multiple projects out there for writing CSS at a higher level, which "compile" to CSS but let you use variables and things like that.
"I am using a large number of div tags within the website (previously it was completely tables based)." That's one part of the problem. Why not use tables if you are using .title, .body and .footer for DIVs when tables have this as default?
I see a lot of people using DIVs on places they shouldn't. They use things like <div class="title" ... Why not use H1 - H6 instead?
HTML tags provide structure. Structure means less complexity. Using only DIVs will get you into CSS trouble.
Edit: A good tip: your website will look more consistent and clean when you try to build your pages by only declaring HTML tags in your CSS at first. Only when there is no other solution declare classes and IDs. And even then remember you can use multiple classes in your class attribute. Things like: class="width50perc floatLeft textAlignRight textColor1" are very handy.
> Things like: class="width50perc floatLeft textAlignRight textColor1" are very handy.
At that point, how is this any different from just using inline styles? The whole point of CSS is to separate presentation from content, you've done gone and thrown a bunch of presentation back into it.
I really like less as an improvement to css. I always end up discarding it though because of the dual representation you end up with. I've tried using the https://github.com/cloudhead/more/ plugin for rails which generates the css on the fly, but it doesn't work reliably enough for me to be confident the changes I've made have been reflected in the page I'm looking at. I also spend a lot of time in firebug tweaking rules and it can be a pain to translate back when you've abstracted the rules you're working on. I think the extensions they've made to css are absolutely the right choices, very minimal. If the browsers would support it I think it would be a winner.
* Partition into sections for fonts, colors+images, positions+spacing, text, and specials.
* Refactor for minimal property duplication, instead of selectors. For example text-weight:bold; will be mentioned only once, but the "#content a" selector multiple times.
* Use a CSS reset.
* Make an extra file per browser+version for hacks. Do not use hacks, which make sure they get triggered in IE7, but not 6 or 8, for example, but use ie6.css, ie7.css, and ie8.css. Duplicate code for this if necessary.
[+] [-] mikeklaas|15 years ago|reply
You can try to reduce the horribleness of a CSS file, but the language simply doesn't provide the tools needed to do the one thing all programmers need to manage complexity: abstract away the common part of two specific processes into a reusable component.
I'll never forgive the designers of CSS for not at least providing immutable constants, if not variables.
[+] [-] brennen|15 years ago|reply
Not that plenty about CSS doesn't beg for better abstractions, but turning it into a programming language is kind of a terrifying prospect. I've see too much of what enthusiastic amateurs can inflict with JavaScript.
[+] [-] ZoFreX|15 years ago|reply
So what if CSS doesn't have variables? We can add them. CSS is the format it has to reach the browser in, it's not the format we have to write in though. There are multiple projects out there for writing CSS at a higher level, which "compile" to CSS but let you use variables and things like that.
[+] [-] tjogin|15 years ago|reply
[+] [-] tintin|15 years ago|reply
HTML tags provide structure. Structure means less complexity. Using only DIVs will get you into CSS trouble.
Edit: A good tip: your website will look more consistent and clean when you try to build your pages by only declaring HTML tags in your CSS at first. Only when there is no other solution declare classes and IDs. And even then remember you can use multiple classes in your class attribute. Things like: class="width50perc floatLeft textAlignRight textColor1" are very handy.
[+] [-] notJim|15 years ago|reply
At that point, how is this any different from just using inline styles? The whole point of CSS is to separate presentation from content, you've done gone and thrown a bunch of presentation back into it.
[+] [-] kevinburke|15 years ago|reply
[+] [-] callahad|15 years ago|reply
[+] [-] ollysb|15 years ago|reply
[+] [-] andyford|15 years ago|reply
[+] [-] astrofinch|15 years ago|reply
http://xcss.antpaw.org/
[+] [-] bill-nordwall|15 years ago|reply
See Nicole Sullivan's Object-Oriented CSS approach: https://github.com/stubbornella/oocss/wiki
[+] [-] haydenchambers|15 years ago|reply
[deleted]
[+] [-] NHQ|15 years ago|reply
[+] [-] Swizec|15 years ago|reply
Any good stackoverflow answers for that? Making people who think "code" is a side-product take pride in that part of their work too?
[+] [-] beza1e1|15 years ago|reply
* Partition into sections for fonts, colors+images, positions+spacing, text, and specials.
* Refactor for minimal property duplication, instead of selectors. For example text-weight:bold; will be mentioned only once, but the "#content a" selector multiple times.
* Use a CSS reset.
* Make an extra file per browser+version for hacks. Do not use hacks, which make sure they get triggered in IE7, but not 6 or 8, for example, but use ie6.css, ie7.css, and ie8.css. Duplicate code for this if necessary.
Example: http://beza1e1.tuxen.de/style.css
[+] [-] jgalvez|15 years ago|reply