Axoplasm

is a fluid found in nerve cells

Archive - 2010

March 12th

Don’t make the stylesheet grep for you

Filed under:

For the last decade or so, every time I wanted to design something like a “subheader,” I’d code it like this:

<h3 class="subheader">This is a subheader</h3>

And then I’d define a style in the main stylesheet like this:

.subheader {
	color: #f00;
	font-size: 18px;
}

Which would, of course, overload any styles I’d already defined for <h3>:

h3 {
	color: inherit;
	font-size: 20px;
}

Sooner or later, we’d realize that we wanted the subheaders in another part of the site (like on the “siderail”) to look a little different. So the HTML didn’t change, really:

<div id="siderail">
<h3 class="subheader">This is a subheader</h3>
</div>

So then we’d overload the .subheader selector:

#siderail .subheader {
	color: #900;
	font-size: 14px;
}

So far, this seems pretty simple, right? h3 is defined with a certain bunch of characteristics, unless it’s a subheader, in which case some of those characteristics get overloaded. Or if the subheader is in the siderail, in which case some of those characteristics get overloaded. This is what the “cascading” in “Cascading Style Sheets” means, right?

Until, of course, one of the developers forgets to add the subheader class to an h3 in the siderail. Or creates a new page region in the siderail where we want to apply a new style — forgetting that #siderail .subheader already overloads h3.subheader. And rather than diagnose where in the cascade the design is breaking, we just add a new selector, maybe a new class like .specialsubheader, that does what we want. And maybe can’t quite remember which shade of dark red (#900) wanted for subheaders in the sidebar, so we make a best-guess (#a00) ... which lets the look and feel drift a little bit.

(There’s also an orthogonality problem with this, which had never occurred to me before. I was mixing in semantic units [“subheader”] where I should have been sticking to cosmetic units [“darkred”]. An h3 should always be a “subheader,” whether it’s in the siderail or not). I noticed this most painfully in places where I used junk like <div class="subheader">. Why do I need “subheader” to tell me what that div should be doing? divs and spans are just empty containers — if you strip their styles away, the content should still cohere semantically).

Well, after only a year of this, we’d reached a point where our main CSS file was 2000 lines long. Most pages loaded 500 to 1000 CSS selectors. When I autopsied the stylesheets I found about 20 different shades of “brown.” That’s just nuts.

So, this time out the gate, I defined a bunch of selectors — mostly classes — with really generic behaviors. Font sizes, padding, foreground colors, background colors, that kind of thing. I also defined some “default” behaviors for semantic units (usually vanilla HTML tags like h3).

So, to extend our example above, the stylesheet might have some selectors like:

h3 {
	color: inherit;
	font-size: 20px;
}
.fg_red { color: #f00; }
.fg_darkred { color: #900; }
.small_font { font-size: 14px; }
.medium_font { font-size: 18px; }

This treats the cosmetic styles kind of like Legos. Where I need a certain effect, I can mix and match styles to achieve it:

<div id="siderail">
<h3 class="fg_darkred small_font">This is a subheader</h3>
</div>

As a coder, this verbosity kinds of offends me. But in addition to saving a lot of mad selector proliferation — itself a form of (harmful!) verbosity, this verbosity serves four useful purposes:

  1. It separates cosmetic and layout styles (“darkred”) from semantic selectors (“subhead”). In fact, it generally lets vanilla HTML (“h3”) do the semantics.
  2. It expresses cosmetic and layout styles where they are most valuable: in the template.
  3. It allows me to easily experiment with styles in the template.
  4. It creates a single, predictable namespace for future selectors.

I just finished refactoring MercyCorps.org according to these principles. I was surprised at how the design disciplined itself. I took a few shortcuts — mostly to work around core Drupal or contributed modules I couldn’t or didn’t care to rewrite — but this self-discipline was just amazing. Instead of building every new template from the ground up, I could go to my big box full of style Legos and put together an effect really rapidly. If I lacked a particular Lego, and couldn’t get a good combination together to replicate it, I’d add it to the Lego box, but as a generic (not nested) selector. That way I’ll have it around to use later.

When I first stumbled across Nicole Sullivan’s “Object-Oriented CSS”, I was dubious about the philosophy. (I still hate the term “Object-Oriented CSS” — CSS is promiscuous, global, and amorphous by design — you just can’t treat selectors like objects, period.) But as I started building my box of Legos I came to think she doesn’t take it nearly far enough. I ultimately split my style “families” into color, text treatments, semantic selectors, layout selectors, and custom selectors. Most of my selectors are generic classes and have one, or at most two, rules. I refactored the entire Mercy Corps site — some 300 templates, I reckon — solo, in under a month, while dealing with our response to the Haiti Earthquake. It required minimal changes to the CMS (mostly redistributing blocks and redefining a few imagecache presets — and these changes were prompted more by our transition to the 960 grid than because of the CSS.) Because the new selectors are in a single namespace, if I need to undo them in multiple templates (for example: change all fg_dark_red to fg_dark_green, I can do this easily with grep.

Speaking of grep, the biggest shift in this exercise has been the way I’ve reimagined my workflow. For much of my career I’ve spent most of my time looking at CSS code. If I needed to change a style, I’d have to figure out a way to do it there, and construct careful namespaces to avoid clobbering selectors elsewhere. Now I don’t need to look at the template (to find the selector) and the CSS — I just edit the template. I realized that for the last decade or so I’ve been using CSS as grep. “Find all the places where subheader is inside siderail and make it darkred” That’s so backwards. I said this elsewhere:

Don’t make the stylesheet grep for you.

March 8th

Mountain Bikes

Filed under:

Dave Moulton wrote today about the evolution of mountain biking. He asked for his readers’ “take on the period” — here’s mine:

Big Boy Bikes

I grew up in rural Nebraska in the 1970s when banana seats gave way to BMX. My favorite thing wasn’t jumping ditches though so much as taking long rambles up dirt roads, I’d be gone for hours. In retrospect I was probably never more than 2 or 3 miles away from the house but it felt much farther. I had a fear of county roads and blacktop traffic, so I stuck to dirt roads: section road, irrigation access, that kind of thing.

We moved to the “big city” Lincoln in the early 80s and I bought my first grownup bike, a late 70s vintage 10-spd “racing” bike. I think it was a Sekai. I rode this and a Schwinn Varsity until high school. My new favorite bike thing was to ride those 10-spds all day, either around town into new neighborhoods, or to outlying towns. At age 13 I rode my Varsity 52 miles (round trip) on a surprise visit to a girl in a neighboring town. I taped cans of Coke to the frame for sustenance, and ate a slice of pizza before the ride home. The girl was out of town, that taught me to always call ahead.

For about 5 years I barely rode at all. It was too “uncool” to be seen on a bike at my gearhead high school, or so I felt anyway. I kept that unhealthy obsession with cars until college when I got my first MTB, a Giant Rincon (1992).

The Rincon reawakened the joy of being gone all day on a bike. This time it was back to dirt roads, and wasteland like timber claims or Wilderness Park (an undeveloped city park southwest of Lincoln). I also lived exactly the right distance from campus for steady bike commuting: too near to drive, too far to walk. After college I took the Rincon — and its successor: a Yokota mountainbike — with me on my archaeological adventures across the Great Plains. I never had the Xtreme Mad Huck personality ascendent in 90s MTB culture, I never railed on sketchy descents or caught big air. My ideal ride was a long distance on two-track in the hinterland. Exploring. Cow-trailing. Unsuspended steel MTBs excel at that.

Yokota

I took the Yokota with me to grad school — I had long since given up cars entirely — where it was my primary mode of transport. Ironically, once I moved to Oregon — where we have actual mountains — I pretty stopped mountain biking. This was the mid-90s and MTB culture was no longer under the radar, and in Oregon at any rate you couldn’t just go ride a bike on all that sweet singletrack. Either it was closed to bikes, or it was developed into a kind of skills park for Mad Hucking. Mostly, to ride a MTB bike in Oregon it helps to have a car; you have to drive to a “trailhead” where you spin around for an hour or so then drive home. It has always struck me as absurd to drive somewhere to Have Fun by biking (or hiking, or skiing) around in little circles. Other than riding a bike to work, I never spent much time on a bike between 1995 and 2001.

Cape Sebastian

Not quite a decade ago I bought another road bike — actually kind of a cross/touring bike, a Bianchi Volpe. That set me on my last — and most durable — love affair with bikes. With a road bike (or better, a ’cross bike), as soon as you step out the front door you’re Having Fun. That bike kept me sane through my divorce, when my all-day-bike-riding habits became a little obsessive. The peak of that period was my solo tour down the Oregon Coast.

This was how I met Jenny: she saw me carrying my bike into our apartment building (we were neighbors), and she asked “do you know any good rides around here?” I didn’t ask her out right that second but I eventually did, and the story had a happy ending. Much of our early courtship — and most of our vacations, even today — are had on bike. Sometimes on that Bianchi, or on one of its roadie successors.

At the Friday Harbor airfield

Last spring I won a fancy new Kona mountain bike. I never would have bought this bike myself, and I’m kind of at a loss for what to do with it. Mostly it’s seen semi-legal singletrack in the weirdly-zoned terrain of SW Portland. I guess you still have to drive a car somewhere to have fun on a mountain bike, and I still think that’s stupid.

New Steed in the Stable

On Saturday, I rode my Vanilla road bike 90 miles — all on blacktop — into the beautiful rural hinterlands around Portland. I don’t get to do this as often as I used to but it’s still my favorite bike thing to do.

March 3rd

Yesterday I received a transmission from the 2030s

Filed under:

Orion’s been home sick a few times lately. Because my work schedule is more flexible I’m the one who gets to stay home with him. It’s easy for me to get a little tired of this, especially as Jenny has parent conferences right now so I’m doing extra-long childcare shifts (15 hrs.) with a (slightly) sick kid, and no car.

I lack Jenny’s talent for getting Orion to fall back asleep at naptime so I generally wind up holding him and rocking in the chair while he falls asleep ... and then sitting motionless for [X] minutes while he finishes his nap. Well when this happened about an hour into O’s nap yesterday, [X] turned out to be about 180. That’s a long time to sit pretty much unmoving, upright, with 25 pounds of kid sleeping on your lap. It could get a little boring.

But when this happened yesterday I had the good fortune to receive, at that exact moment, a memory transmitted backward in time from myself in ten or twenty years. Holding my napping toddler son while my legs fall asleep seems painfully boring at the moment it’s happening, but apparently it’ll become one of my favorite memories. And someday I’ll wish more than I can imagine right now to relive that feeling for even a few minutes.

February 22nd

Rick

TooncesMy friend Rick committed suicide this past week. I heard about this on Saturday.

I’d known Rick for at least 12 years that I could reckon and maybe longer. He was the kind of friend I’d cross the street to talk to, in fact I saw him around — at the library, on the bus — quite a lot because he only lived a few blocks away. Despite which I didn’t really know him all that well beyond sort of the facts of his life. I didn’t know his internal life and so on. That’s kind of a theme that's emerging. He lost his longtime job a few years ago and went back to school for electrical engineering. He was in a band ... he was always in a band. He was an audiophile and music lover, and had beautiful guitars that he always put to good use.

I last saw him at a party about 3 wks ago, he had just quit the band to concentrate on school full time. School was really hard on him, we talked about how much harder it is to learn new subjects in your 30s compared to your 20s. Anyway he got all As last term. I can’t imagine what was in his mind the last weeks or months. He may have seen his life as something failed or difficult but I envied lots of things about it, things I didn’t have any more or never had to begin with. He was single/childless and had lots of freedom. He was funny and everyone liked him. He was a talented musician and good at math. I especially envied that, having never been very good at math and even worse at music. I wish I'd have told him this, but like I said he kind of held most people at arm's length.

He had a few very good friends and lots of casual ones, and I was in the second group. I’m not feeling too sad yet in a way like “I miss Rick” but I feel really bad for those people who were very close to him. Those people are in my thoughts now.

February 10th

Lent, a little early

I realize Ash Wednesday is next week but I’m gonna get started early on Lent. I never do Lent, not being a Christian except in the “culturally Christian” sense, but with the seasonal theme of sacrifice and redemption it feels like a good time to do some spiritual housecleaning.

But what to “give up?” It turns out I’m pretty much living the medieval version of Lent already, as I scarcely ever eat meat, drink beer, or lust any more. (I do drink a lot of coffee and enjoy the occasional donut, sure.) I’m lousy at this materialism thing so I score pretty low on the avarice and envy scales too. Not a lot of personal sins to give up here. Besides which, focusing on personal sins is a little narcissistic: I don’t need to better my self, I need to better my relationships.

To that end, here are my Lent resolutions:

  1. No more screens at home. I pretty much stopped watching TV so that’s easy to quit. But also: no more idly surfing TV Tropes on the iTouch. No more Google Reader at breakfast. No more “catching up” with the news on Sunday night. When I’m at home, my focus should be on my relationships with Jenny, Orion, and Bismarck not glowing rectangles. I make two exceptions here:
    • I can check the weather
    • If I’m working. On work. The kind that gets me paid.
  2. No more social media narcisssism. Specifically: my personal TwitterFacebookFlickrverse doesn’t care so much about how nice my commute was. I could just say: “no more Twitter and Facebook” but then I’d miss out on what my friends are doing, which is the purpose right? So to this end I’m limiting myself to four social media activities:
    • “Liking” things on Facebook
    • Retweeting and “faving” items on Twitter
    • Direct Messages on any medium
    • Tweeting progress on my New Year’s Resolution
  3. Tithe for my neighborhood. Specifically, renew my commitment to some organizations that I’ve let languish:

Axoplasm is also Paul Souders.
I design websites for

I have stuff all over the Internet on

I built this site in a weekend but it took me Eight years to write it all.

Latest Tweets

(cc) 2002–2010 Paul Souders. Axoplasm is licensed in the Creative Commons Powered by Drupal, an open source content management system