views:

164

answers:

5
+3  Q: 

Making my own CSS

Don't worry, I'm not breaking the web :P

I'm annoyed by some stuff in CSS, and I'm going to fix it. It'll be syntactic sugar only, my language will be server-side compiled to regular CSS, so there's no need for special software on the client side.

My current ideas:

  • Variables (actually, they're constants). You will be able to define colours and other things at the top (or anywhere) of the file and then refer to them from anywhere.
  • Server-side includes. The @import statement does this as well, but it requires more HTTP requests. If CSS files are concatenated on the server, it's faster.
  • Nested CSS blocks:

My code block:

#newsBlock {   
  background-color: red;
  ul.items {
    list-style: none;
    li {
      float: left;
    }
  }
}

Would be equivalent to normal CSS:

#newsBlock {
  background-color: red;
}

#newsBlock ul.items {
  list-style: none;
}

#newsBlock ul.items li {
  float: left;
}

Comments and other suggestions?

+5  A: 

So in other words you're looking for Sass. Of course it would be whatever port for your particular server side language.

Agent_9191
The "mixins" of sass should be usefull for wrapping css3 attributes (such as border-radius), so that css3_foo(x) evaluates to "foo: x; -css3-foo: x; -moz-foo: x; -webkit-foo: x" ...
Rasmus Kaj
+10  A: 

Why not use one of the already existing frameworks that do this instead of re-inventing the wheel?

I'm sure there are others as well.

adrianbanks
+1 for Less CSS, a very neat solution.
Yann Schwartz
Exactly what I was going to suggest.
evolve
That looks like what I want, but is there a port to compile them with PHP? I want the site editor to be able to edit and save his LESS-source and then let PHP see that the file was changed and recompile it on-the-fly.
Bart van Heukelom
Wow, I never heard of these before! I'll definitely study these a lot.
tahdhaze09
@Bart: a php version: http://leafo.net/lessphp/
adrianbanks
Thanks adrian, I'm using that now and am very happy about it
Bart van Heukelom
A: 

How about inheritance?

Jeff
+1  A: 

Actually what you're suggesting isn't really new. Take a look at the following:

Using variables in CSS style sheets

CSS Colors: Take Control Using PHP

Generating Dynamic CSS with PHP

It's an interesting concept.

Chris
+1  A: 

there are other frames works like this. Kevin Yank's presentation on it here, you might find some ideas there.

http://vimeo.com/7530607

Thorn007
ok... now the links work.
Thorn007
Very informative talk
Bart van Heukelom