Monday, July 15, 2013

Modern Day CSS: Stylish Color

Back in March, I was challenged to help create a new html email template for a client of mine.  In my naivety, I believed it to be simple.  I mean, I have been coding websites for a while and figured email would be about the same.  I mean, it is still html, right?

Wrong.

Email, for whatever reason, is far behind the evolution of web browsers.  While the basic html coding is very similar, it lacks much of what makes modern websites so wonderfully easy to create.  Specifically, I am referring to CSS, or cascading style sheets.  For those non-tech-geeks out there who actually have a life to lead, CSS is what coders use to make things the right shape, size, color and appear in the right place on the screen.  Here is an example of why web developers love CSS.

Say I wanted to create a string of text, but I want to make the text red.  Using the old school approach, I would use the html attribute of "color" like this:

<p color="red">This is some text.</p>

Using the css version, it would use the css style of "color" which would look like this:

<p style="color:red">This is some text.</p>

Now, some of you might say, "Wait, but that uses more text.  Wouldn't that make it slower to code, not faster?"  True, if that was all we were doing, it would be slower.  There are two things to consider.  One is that every additional style could be put in the same style attribute.  So, if we wanted the text to be sized to 18px, have a black background, and align in the middle, the code would be, for attributes:

<p color="red" bgcolor="black" align="center" ><font size="4">This is some text.</font></p>

And for CSS:

<p color="red;background:red;text-align:center;font-size:18px">This is some text.</p>

Now, the CSS has become smaller.  Also you will note the severe disadvantage of the old attributes when it comes to font size.  It not only requires a separate "<font>" tag, but the sizes were limited to a set scale between 1 and 7.  Size "4" is about equal to 18px, but size "5" would be about 24px.  If I wanted the text to be 20px or 22px, I would be out of luck.

The second big advantage for CSS is the ability to change specific elements, or to change a specific group of elements.  Say that instead of making one <p> tag red, I wanted to make all of the <p> tags red.  With attributes, I would need to declare it separately for each.  For CSS, I can declare it once.  Here is the attribute version:

<p color="red">This is some text.</p>
<p color="red">This is some more text.</p>
<p color="red">This is the third line of text.</p>
<p color="red">Here is the rest of the text.</p>

The CSS version would declare it once, like this:

<style type="text/css">p{color:red;}</style>
<p>This is some text.</p>
<p>This is some more text.</p>
<p>This is the third line of text.</p>
<p>Here is the rest of the text.</p>

The end result is that I would be able to change all of the p tags on all of the webpages in my site simultaneously, which saves a lot of time.

Stay tuned for my next post, where I continue my story of creating an html email template and describe my endless frustrations with a former html friend: tables.

Until next time...

Friday, July 5, 2013

Here I Go Again

Twice before, I have tried to start a blog.  Twice before, I have failed.  Here is hoping that the third time truly is the charm.

The theme for this blog is the web.  For an entity that is only decades old, and barely older than I myself am, it has come a long way from its origins.  Now, with the world changing, I want to take a look back, a look around, and try to take a look into the future of the world wide web.

I do not intend for this to be an end all expert account of all that the web is, was, or will be, but rather the ramblings of a guy who grew up on the web, from Prodigy to AOL to IE and Chrome, I have seen my share of the .com's and the .bomb's.  I have seen sites that have been glorious and ones that make me want to pull my hair out.  If my posts make you reminisce, if they make you laugh, if they make you cry or shut your eyes in pain, or if they simply make you say "They really did that???", then I have done my job and fulfilled the purpose of this newest of my blog attempts.

As I said, I have tried and failed before, but perhaps this time I have found my niche.  I welcome you to come and find out.  So, without further ado, here I go again...