myCSS

A New Approach to CSS Markup

I've always thought CSS markup was a jumbled mess. The last thing I look forward to on a project is debugging CSS.

HTML doesn't care if there is whitespace between a tag and its closing bracket. I use that a lot to align my markup into columns. With columns errors stand out. You don't have to look for them. They jump out at you.

While reading through jQuery's source I noticed that many of the lines begin with a comma. That was new to me. jQuery is a master of minimalization: maybe I should do that.

Becoming aware of how the different parsers work let me break free of traditional approaches. Much of what I see comes from times before GUIs and our only tools were simple line editors. Old habits die hard. So I changed my way of doing markup to take advantage of how parsers work.

That's how "My CSS" came about. No free form. Constrained. Searchable with common tools. Easy for me, hence the name.

Jargon and Constraints

    

Examples

}@media { single line @ selector
}#id { single line id selector
}.class { single line class selector
} element { single line element selector
}#id first line of multi-line selector
,.class subsequent multi-line selector
, element { last line of multi-line selector
/*comment -- every comment line must end with */
}Xspan { smudged element
}Xleft: 0; smudged rule
}#myId {
}XmyId { id selector + smudge; del line to de-smudge
}.myClass {
}XmyClass { class selector + smudge; del line to de-smudge
      column 1 : the rail [ },/]
      may contain space, right brace, comma, forward slash
    
      column 2 : the gutter [ @#.*X]
      may contain space, at sign, hash mark, dot, star, smudge
    
      column 3 : the body continues until the end of the line.
      may contain id and class labels, elements, rules, comments
    

Setup

  
<style>X{; }</style>
Set up your <style> tags like this. To be valid css a rule must be named (have a selector: that's the X). Empty braces are not allowed and don't validate, hence the semicolon. This technique passes the W3C Validator

  
}#sales { width : 8rem; color : blue; }.teams { padding : 1rem;
All selectors close the previous selector's ruleset and open their own: right brace is on the left of the selector, left brace is on the right. It saves a line and frames each selector nicely. IMO it makes better looking markup. It also makes for easy grepping.

Debugging and experimenting with your styles