Timmargh.net

Custom CSS Signatures in Mail.app - UPDATED  21

After reading Melvin Rivera’s excellent tutorial over at All Forces I set about creating my own HTML/CSS signature in Mail.app and came up with:

New message

(Melvin shows how to include an image but I’d rather stick to just text.)

I came across a problem, however: when my signature was converted to plain text, for example when someone replied to one of my emails, it looked like:

New message

Obviously, the text is now a bit pointless as no hyper-links are present. However, there is a way around this using CSS’s display attribute …

First of all, my site address. As I named the site using part of the address I only need to add a bit of extra code - the original looked like:

Read stuff at <a href="http://timmargh.net/" style="color: #8f2831; text-decoration: none; border-bottom: 1px #888888 dotted;">Timmargh.net</a>

Which, when viewed as HTML, gives us:

Read stuff at Timmargh.net

… which is how it should be, link and all. However, as plain text it looks like:

Read stuff at Timmargh.net

So, we add some extra code (shown in a different colour) like so:

Read stuff at <span style="display: none">http://</span><a href="http://timmargh.net/" style="color: #8f2831; text-decoration: none; border-bottom: 1px #888888 dotted;">Timmargh.net</a><span style="display: none">/</span>

(The extra ‘/’ isn’t strictly necessary, but I’m anal about that sort of thing.) This, viewed as HTML, gives us:

Read stuff at http://Timmargh.net/

… which is identical to the original, but as plain text we now get:

Read stuff at http://Timmargh.net/

It doesn’t look as good, but the URL is there for all to see.

A slightly different approach for the link to my Flickr account. The original code:

View my photos on <a href="http://www.flickr.com/photos/timmargh/" style="color: #0000ff; text-decoration: none; border-bottom: 1px #888888 dotted;">Flick<span style="color: #ff0000">r</span></a>

… viewed as HTML looks like:

View my photos on Flickr

… which, again, is how it should be, but as plain text looks like:

View my photos on Flickr

So, again we add some extra code, this time on the end:

View my photos on <a href="http://www.flickr.com/photos/timmargh/" style="color: #0000ff; text-decoration: none; border-bottom: 1px #888888 dotted;">Flick<span style="color: #ff0000">r</span></a><span style="display: none;"> at http://www.flickr.com/photos/timmargh/</span>

… which, when viewed as HTML, looks like:

View my photos on Flickr at http://www.flickr.com/photos/timmargh/

… (identical) but as plain text looks like:

View my photos on Flickr at http://www.flickr.com/photos/timmargh/

And … that’s it. Not particularly clever or neat, but it puts my mind at rest.

Update #1

The entire code for my signature as requested by David, although I’ve coloured and split it onto several lines for easier reading - be sure to remove any line-breaks and spaces from the beginning of lines:

<div id="sig" style="line-height: 14px; margin: 8px 0; padding: 4px; background-color: #ddddbb; border: 1px #999999 dotted; font-family: 'Lucida Grande', Verdana, Arial, Sans-Serif; font-size: 11px; color: #000000;">
  <strong style="line-height: 16px; font-size: 12px; padding-top: 8px;">Timothy Griffin</strong>
  <br />Read stuff at <span style="display: none">http://</span><a href="http://timmargh.net/" style="color: #8f2831; text-decoration: none; border-bottom: 1px #888888 dotted;">Timmargh.net</a><span style="display: none">/</span>
  <br />View my photos on <a href="http://www.flickr.com/photos/timmargh/" style="color: #0000ff; text-decoration: none; border-bottom: 1px #888888 dotted;">Flick<span style="color: #ff0000">r</span></a><span style="display: none;"> at http://www.flickr.com/photos/timmargh/</span>
  <br />Contact me using <a href="mailto:emailaddress@mac.com" style="color: #8f2831; text-decoration: none; border-bottom: 1px #888888 dotted;">emailaddress@mac.com</a> for email, MSN, iChat & AIM
</div>

Update #2

As Ryan pointed out, below, using this method doesn’t always give us the results we want. He suggests an alternative method: format the “hidden” text as white (or the same colour as your background) and in a very small font size. So, using my Flickr link as an example, we’d put:

View my photos on <a href="http://www.flickr.com/photos/timmargh/" style="color: #0000ff; text-decoration: none; border-bottom: 1px #888888 dotted;">Flick<span style="color: #ff0000">r</span></a><span style="color: #ddddbb; font-size: 0.1px;"> at http://www.flickr.com/photos/timmargh/</span>

… which looks like:

View my photos on Flickr at http://www.flickr.com/photos/timmargh/

The hidden text is just about visible (if you look very closely), but in the context of my signature, i.e. with the properly coloured background, it will be invisible.

The only downside of this method is that you can’t really hide long strings mid-way through a line of text as you’d see a gap; e.g. the code:

This text is visible and can always be seen. <span style="color: #ffffff; font-size: 0.1px;">This text is hidden and can only be seen as plain text. </span>This text is also visible and can always be seen.

… looks like:

This text is visible and can always be seen. This text is hidden and can only be seen as plain text. This text is also visible and can always be seen.

It my look different in your browser, but in mine (Safari) it looks like this:

Quote

So, if you want to use this technique you’ll have to come to a comprise on the layout and content of your signature. Personally, I think I do actually prefer Ryan’s technique and I’ll be adjusting my signature to fit it in.

The conversation is closed

#1 Melvin rivera said:

brilliant solution timothy!

on 5 May ‘06 Lock

#2 LobsterMan said:

Cool trick, I gotta try it…
BTW, I like the new header image.

on 5 May ‘06 Lock

#3 Timmargh said:

Thanks Melvin, LobsterMan.

The header image is from Digital Blasphemy and I’m working on a choice of colour schemes to match some different images.

on 5 May ‘06 Lock

#4 MHC said:

Oh Timmy and Melvin, you’re my heroes! I will now have a sig in my emails!!!

on 5 May ‘06 Lock

#5 MHC said:

Just one thing… I need to specify a background colour and uhm… How do I phrase this particular property? A body tag?

on 5 May ‘06 Lock

#6 MHC said:

Nope doesn’t work…

on 5 May ‘06 Lock

#7 Timmargh said:

The whole sig doesn’t work or just the background colour? I don’t think you can colour the entire message, just the signature.

on 5 May ‘06 Lock

#8 MHC said:

The background colour… Sig works great! At least it looks fine in a Safari page! I am trying to add a background colour in the sig and I just can’t see how to.

on 5 May ‘06 Lock

#9 Timmargh said:

Have you wrapped the sig in a <div> ? At the start of mine I have something like:

<div id="sig" style="background-color: #ddddbb; … "> …

And obviously at the end there’s a </div>

on 5 May ‘06 Lock

#10 MHC said:

I tried that! IT WORKS!!!!! WHOOH HOOH! Thanks a billion, Timmy!!! Expect an email! ;^)

on 5 May ‘06 Lock

#11 MHC said:

Oh and I love the new design in here! Bravo, Timmy!!!

*Clap*

on 5 May ‘06 Lock

#12 Timmargh said:

Thanks MHC - I’m working on a choice of seasonal colours schemes at the moment …

on 5 May ‘06 Lock

#13 stonysleep said:

After MHC pointed me in the direction of this post i think i’ve got it working. I’ve also bombarded her with a ton of emails today consisting of “does it look ok to you” and “why doesn’t that work if i reply” oh and “the sig text changes colour if you have colour quoted text switched on”
So, i may have to start sending emails to you instead

As for the design - it’s very nice in here, and digital blasphemy is an awesome source of images. I need to redownload all those 3d rendered islands and mountains i used to have at work for my desktop instead of the boring blue background (though tbh i rarely see my desktop so there isn’t a lot of point!)

on 7 May ‘06 Lock

#14 Timmargh said:

"So, i may have to start sending emails to you instead"

Please feel free … can’t guarantee I’ll be able to help though!

on 8 May ‘06 Lock

#15 Ryan said:

This is a great idea, but I’m running into a problem. It seems Mail.app does not include the “hidden” text in the plain-text version of the message.

What I’m trying to do is put a “—” at the top of the signature to make sure that it’s differentiated from the body of the email. The “—” is not necessary if the HTML version is viewed (since I have a CSS border acting as the dividing line) but I want it to show up if the plain-text version is viewed.

The only thing I can think of is to use white-colored text instead of the “display: none;” tag.

on 10 May ‘06 Lock

#16 Timmargh said:

Yeah, it seems to depend on the other users mail program - I’ve had some replies where the hidden text shows and some where it doesn’t.

White coloured text is good idea - I might try that.

on 10 May ‘06 Lock

#17 David said:

I know it is a waste of bits but I love this stuff. Could you post the code for you entire sig…modifying code is the only gear I have right now. Cheers!

on 11 May ‘06 Lock

#18 Timmargh said:

David: I’ve added the code at the end of the article.

on 11 May ‘06 Lock

#19 Ryan said:

Okay, I finally got the “—” to consistently show up in the plain text version of my signature by adding a line at the top of my HTML (before the main DIV tag) that looks like this (except with the correct type of bracket):

{span style=”color: #FFFFFF; font-size: 0.1px;”}—{/span}{br /}

I originally had the font size set at 0px, and it works beautifully in Firefox, but it causes Safari to balk and display the “—” at full size.

on 12 May ‘06 Lock

#20 Timmargh said:

Nice one - I’ll make a note of that.

on 12 May ‘06 Lock

#21 David said:

Thanks. I am digging it.

on 12 May ‘06 Lock