Cascading Style Sheets (CSS) and PHP

Often when dealing with Cascading Style sheets, or CSS, I find myself wishing that the CSS mechanism included variables. This is especially true when dealing with colors, since you want the same color applied to lots of different things. It can be a real pain to go back through an old style sheet and find the code for the color you want. I was quietly surprised that no one making up how CSS worked had addressed something like this.

Then, a while back I was giving a buddy of mine a few exercises to introduce him to the exciting world of Web programming, touching on CSS, HTML, PHP and MySQL. I gave him pretty much no guidance; I just thought up plans that would introduce him to the concepts and gave him a list of my favorite references. (I’ll be posting those exercises here in the nearish future.)

Anyway, without me to tell him how to do things, he went and dug around and one of the first style sheets he sent me for evaluation had a .php extension rather than .css.

Bingo! Once you see it in action, it’s obvious. PHP can be used to generate CSS files just as easily as it can be used to generate HTML files. Now my style sheets can change based on external conditions or can simply define a set of colors that all the style definitions share. Why did it take me so long to figure this out? It seems like this technique should be a lot more common than it is.

Here’s a quick code snippet for those who want to try it for themselves:

	header('Content-Type: text/css');
	$header_back_color = '#dddddd';
#corner_table th {
	background-color:<?php echo $header_back_color ?>;
	text-align: center;

A couple of notes: the <?php MUST be the very first thing in the file. No empty lines, no spaces. The reason is that the next line, with the header() function, has to be called before the server sends any page content. (Once the server starts sending content back to the browser, it’s too late to be fiddling with the headers. Any whitespace outside the <?php tag will be considered content.) The header line is necessary because you need to tell your browser that what you are sending really is a css file.

In the <head> of the html file, you call the style sheet just like normal, but of course the file you fetch will have a php extension:

<link rel="stylesheet"
      media="screen" />

That’s all there is to it. Why have I not done this with every css file?

Self-Portrait Friday!

It’s been a while since I’ve turned the camera on myself, but today I joined Pinup Lifestyle and was looking for a good photo to put up for my profile. I call myself a photographer over there, so I wanted the picture to be a good one. I used one of my old favorites from long ago, but that got me to thinking about some other things to experiment with.

Tonight I closed myself in a dark room with my camera (on tripod, set to ‘bulb’), remote shutter release (operated with my toes), and a pair of flashlights. My goal was to open the shutter, shine a light on one side of my face with one expression, then shine a light on the other side of my face with a different expression.

I was not entirely successful.

a flashlight, a dark room, and a long exposure

a flashlight, a dark room, and a long exposure

This is an early attempt using one flashlight. I just couldn’t keep still enough while also dealing with the lighting. When I went to two flashlights things got better, but getting the two sides of my face exposed equally proved impossible.


direct hit with one of the flashlights, then my toe slipped off the shutter release

Sometimes when things go wrong, however, they can come out all right. My toe slipped off the shutter release on this one, before I got to the second flashlight. After this shot I realized that I was overexposing where the flashlights hit and I cranked the aperture way down. Things got better after that.


two flashlights in a dark room

a decent shot, but with the same expression on both sides

This was a test shot while I was adjusting the aperture. It came out pretty cool, if you ask me.


Jerry Seeger self-portrait

finally held still enough, but didn't get enough light on the frowny side

Given infinite time and infinite patience, I think I would have got the shot. I had neither, however, and when I began to like my test shots more than the actual attempts I decided I’d done enough. Sometimes an experiment doesn’t yield the results you expect, but that doesn’t mean the results aren’t interesting.



This Might Be Fun

I’ve written quite a bit about my participation in the Cyberspace Open, and Long ago fuego and I were winners at the Duke City Shootout. Here’s a contest that combines the two: The 48-Hour film Project. You are given prompt, a prop, and a couple of other constraints, and in the next 48 hours you write, produce, and edit your entry.

I think I have the right group of friends to do this. It’s a bit pricey to enter, but the biggest problem would be getting us all to the right place at the right time. San Jose’s in August. Anyone want to come play?


The Lust Lizard of Melancholy Cove

One axiom I use when evaluating fiction is that the author is allowed one Big Coincidence in a story. It’s that one unlikely event that turns a mundane situation into something worth writing about. In The Lust Lizard of Melancholy Cove by Christopher Moore, the coincidence is that the Old Bluesman who comes into town just happens to have a history with the sea monster that can alter people’s brain chemistry (and make them randy as bunnies in the springtime) which comes ashore just as the town shrink switches everyone from their antidepressants to placebos in response to the death of a patient while…

You get the idea.

There is, happily, an exception to the one-big-coincidence rule, and that’s farce. Farce is not as easy as it looks; you can’t just throw some new bizarre thing at the reader every time you lose momentum. Ultimately things have to hang together, to make sense in the farcical context, and come to a satisfying resolution. Characters still have to grow and change organically. Lust Lizard pulls off the farce in style.

The sea monster’s bunny-in-springtime effect begins to take hold before he even reaches shore, and unlikely pairings ensue. Alas, Steve the sea monster is not so fortunate in love. After an less-than-successful romantic entanglement with a gasoline tanker, the sea monster disguises himself as a trailer in a trailer park, where he is named Steve by the unstable b-movie actress who lives next door (and still works out with her big sword while dressed in her barbarian outfit).

Steve’s not a bad guy, really. Just hungry and lonely. And it’s not as if anyone liked the paperboy anyway…

Naturally the onus for figuring out what’s going on and doing something about it falls on the local law enforcement. That would be Theo. Theo is stoned most of the time, grows his own weed, and follows orders from the department in the big city. Those orders don’t always make sense from a law-enforcement standpoint, but Theo knows a good gig when he sees one. Only problem is, he’s on his own this time.

Throw in a colorful cast of side characters and this coastal California town is primed and ready for wacky hijinks. And hijinks there are aplenty. This book has its serious moments but even they shimmer with a surreal glaze, then off we go romping through the bizarroverse again. It’s a fun read that never loses its momentum.

I wonder, with books like this, which came first, the story or the title?

Note: if you use the above link to buy this book (or a Kindle, or a new car), I get a kickback.


Round Two: My Fake Entry

As I thought about this prompt, I thought of the scene in the the classic movie Get Crazy, when Reggie Wanker emerges from a dressing room filled with naked women only to discover that the girlfriend he’s been ignoring (and who saw him in the room filled with naked women) is now with another guy. Said Reggie: “Betrayed! Turn your back for half a second and they stick a knife in it right up t’hilt.” As he goes back on stage (this has all occurred during a drum solo) he says. “I’ve finally found the meaning of the bleedin’ blues. Ol’ Reggie can take the pain… but can they?

Classic stuff. Malcolm McDowell makes a great Mick Jagger.

Anyway, I pondered for a while about what to do for my scene, but because I didn’t want to work too hard at it, I borrowed characters from a story I’ve already been fiddling with, called The Quest for the Important Thing to Defeat the Evil Guy. Tatra is a new addition, and hey, what high fantasy story can’t be improved with a smart-mouth goth chick? Once again I’m heavy on dialog without much physical action.

Tatra (17, Goth - black hair and nails, black dress with metallic accessories) is staring into the campfire flames. She has a blanket wrapped over her shoulders. Nearby she can hear Bixby snoring gently. The rest of the party are arrayed on the ground, all asleep.
Kitty jumps up into Tatra's lap, purring softly.
Hello, Kitty.
Kitty settles into her lap, and Tatra strokes her fur gently. Kitty's purring intensifies.
So pretty...
Tatra's fingers stop at the base of Kitty's skull.
I could snap your neck in half a heartbeat.
The purring stops. Kitty looks up at Tatra in surprise.
Can you talk like that?
Kitty shakes her head but doesn't try to escape.
I should probably just kill you.
Kitty tenses, and Tatra tightens her grip. They freeze that way for a few heartbeats, then Tatra relaxes slightly.
If I let you go, will you kill me?
Kitty shakes her head no.
Can I trust you?
Kitty shakes her head no again. Tatra smiles. She releases Kitty's neck. Kitty jumps down from her lap. Space distorts and standing before Tatra is a woman, slender and lithe, with long black hair poorly protecting her modesty.
They both look around nervously to make sure the others are sleeping.
Crap it's cold.
Where the hell are your clothes?
Which do you think looks better on a cat, an evening gown or a tutu? Of course I'm naked.
Tatra tosses her the blanket.
Put this on. You're grossing me out.
Kitty takes the blanket but hesitates before putting it on, posing, smiling at Tatra's jealousy-fueled discomfort.
There's still time for you. You might still develop a body like this one.
Oh, goody. Then I can be a slut, too.
Kitty wraps the blanket around herself and stares down at Tatra.
Be careful, Tatra.
If I was careful I would have killed you already.
Kitty hesitates, then sits on the log next to Tatra.
I guess I deserved that. So, what is it you want?
What's your real name?
Who do you work for?
What do you mean?
What the hell do you think I mean? Who do you work for?
I work... for The Master.
Tatra stifles a laugh.
The Master. Surely you've heard...
Tatra's face is blank.
How can you be here, now, with us, and never have heard of The Master?
The Master? That's the best he could come up with? Oooo... The Maaaaaaster! Scary!
Kitty looks around in alarm.
Quiet! You'll wake someone up.
Or what? You'll tell the master on me? Oh, no!
She makes her eyes round with mock alarm and puts her hands to her cheeks, then starts to laugh - but quietly.
What are you doing here?
The Master—
Tatra snorts.
My people have a great interest in the outcome of your quest. There are prophecies.
That gets Tatra's interest.
No kidding? Like what?
For instance, in the great tome "Insane Ravings of Hu'upman and other Vague Pronouncements", it says that if the elf marries John the Smith, then The — my master's designs will be thwarted.
Tatra looks stricken. She speaks past a lump in her throat.
Lada and John...?
IF, my dear. I would prefer that not to happen.
Tatra stares at the ground.
I would prefer that not to happen, too.
Kitty sighs and pats Tatra's knee.
You like him.
He doesn't even know I exist.
Kitty begins to say one thing, stops, then says another.
No, I don't think he's capable of seeing anyone not of royal birth.
Like Princess big-boobie bitch-face? Ugh! I just want to strangle her sometimes.
Tatra looks around now, alarmed by her own outburst. Kitty smiles and moves closer to Tatra on the log. She puts her arm around the girl.
I agree. What would you say if Princess Skoda ended up with your friend Bixby instead?
Tatra puts her hands around her throat and makes a gagging noise.
He might become prince...
He'd be better off with Elf-Lady.
Kitty smiles. Her teeth are white and even, her eyes gleam in the firelight.
Then we are in complete agreement. Lada must not mate with John the Smith.
Ewww. Thanks for that image.
Tell me, why did you not kill me?
Because... because I think you want Bixby to live. And I thought maybe you could help me. You know, with magic.
Help you what?
Tatra turns away, suddenly shy.
You know.
Will you help me in return? When we find the Important Thing?
"Sure?" That's all? You're OK with allowing The Master to plunge the world into darkness and despair?
Pf. Welcome to my world, cat-lady.


A Typo that Should be in Common Use



Round Two Begins!

I was eliminated in round one of the Cyberspace Open (not even a near miss, I’m afraid), but that’s not going to stop me from cranking out a scene for round two! It will just stop me from working very hard on it.

Your PROTAGONIST has been betrayed by his CONFIDANT — someone deep within his (or her) inner circle. This betrayal threatens to destroy everything the protagonist has been working towards. The protagonist’s only ace in the hole: the confidant is not yet aware he’s been found out. Write a crackling scene in which the protagonist confronts the confidant.

I had a thought this morning that might help the one hundred talented folks who are moving on. The top three entries will be produced on video to determine the grand champion. If you think you have a shot, you might consider the produceability of your scene – will it shine in a low-budget video enactment? Zero gravity explosions being an integral part of the action might cost you in the long run.

I wish all of the contestants good luck, but especially the ones who have stopped by here to share advice. You guys rock!