May 13

How To Zebra-Stripe Tables Using CSS and jQuery

Zebra Stripes DemoAs I was browsing my ridiculously large and disorganized RSS feeds a few days ago, I came across a very interesting article that discusses the “benefits” of using zebra-striping on tables. The article was titled Zebra Striping: Does it Really Help? and it was published on A List Apart. In short, the author of the article discusses the use of zebra-striping, its history, and the benefits which are associated with its use. Furthermore, she describes and attempts to make sense of a small experiment carried out by herself in order to test the “benefits” linked to zebra-striping. The article concludes with the author’s assesment of zebra-striping as valuable in terms of visual appeal but with little to no influence on usability. As a concluding statement she writes, “At the end of the day, the decision about whether to use zebra striping probably comes down to a subjective assessment of likely gains versus the cost of implementation.” So, let’s make the cost of implementation minimal by using some simple jQuery and CSS. Before we begin, here is a sneak peak at the final result.

jQuery Zebra Stripes Script

There are many ways to implement a zebra-striping script using jQuery, and I will demonstrate one of them. The following approach uses a function, which takes two (optional) parameter and creates a specified CSS class for all the even rows of a given table. However, if the function is called without any parameters all even rows on tables will be given the class “even-row.” Here is what the script looks like:

  1. $(document).ready(function()
  2. {
  3.     stripeTable();
  4. });
  5.  
  6. function stripeTable(table_name, class_name)
  7. {
  8.     var target;
  9.  
  10.     if(table_name && class_name)
  11.     {
  12.         target = table_name + " tr:even";
  13.         $(target).addClass(class_name);
  14.     }
  15.     else
  16.     {
  17.         target = "table tr:even";
  18.         $(target).addClass("even-row");
  19.     }
  20. }

Note: the above script is calling the function with no parameter and thus will reset to the default rules.

Add Some Style

Now that our script is complete and working, let’s add some color to the newly created class, “even-row.” Remember that this class name is given because we did not specify parameters when we called the function on the script above. So, here is what the “even-row” CSS for the demo looks like:

  1. #content table tr.even-row td
  2. {
  3.     color: #c76400;
  4.     background: #e6e6e6;
  5. }

Note: the ID content is targeting a div of the same name on the example file. Thus, when implementing your own CSS rules remove it.

Use, Installation, and Download

In case you overlooked the sneak preview link at the beginning of this post, take a look at the script in “action” by clicking this demo link. This script is free for your use or modification. However, you need to download and install jQuery for the zebra-striping to work. In other words, the of your document will have to include the following files and look something like this:

  1. <script type="text/javascript" src="[YOUR PATH]/jquery.js"></script>
  2. <script type="text/javascript" src="zebra_stripes.js"></script>

In any case, enough talking (writing), download the script and enjoy!

zebra_stripes.js

May 09

A Web Designer’s Photoshop Actions

Photoshop IconAs a web designer, I spend countless hours designing web pages in Photoshop. Of course, this happens only after thoughtful consideration with regards to the site’s layout and several sketch iterations, otherwise know as the framework. In any case, this process may get overly repetitive as you begin to receive a more steady work flow. So, wouldn’t it be nice to automate some of this process? If you are anything like me, you are thinking: “yes it would be.” Therefore, it is time to turn our attention to one of the greatest features in Photoshop, actions. Photoshop actions can record any given set of steps and store them for later usage. Thus, we can use actions to create a simple yet read-to-use Photoshop file for our web design purposes. This file will contain the “scaffold” for our design. In other words, this file will free us of the mundaneness that comes from setting up a Photoshop environment every time we begin a new website’s design. Note: I use Photoshop CS2. So, some of the steps demonstrated here may vary depending on your software’s version.

Creating My Photoshop Action

So, let’s open Photoshop and get to work. Here are the steps that I’ve taken to create my own action:

  1. Go to Windows -> Actions.
  2. Create a new set and name it Web Design Actions.
  3. Now, create a new action and name it Framework. From this point on the action will begin recording your every move until you press the stop button.
  4. Create a new document (I usually work with an 800×600 to begin with) by going to File -> New. Also, unlock (double clicking it will do the trick) the background layer, and name it Background.
  5. Create groups for all the necessary sections of a regular site and name them appropriately.  I usually start with a group for the header, navigation, content, sidebar, and footer.
  6. Now, give yourself some guides. Simply click on the left side ruler and drag to your desired position. I usually create two initial guides 25px away from the side edges of the canvas.
  7. Finally, stop the action recorder. This will automatically save all the steps previously performed.

Make Your Own and Use It

Now that you know how to create a Photoshop action, make your own and use it every time a project comes your way. Soon you will realize the convinience of having a basic framework action. Furthrermore, by automatizing this routinary process you will save yourself valuable time. Enjoy!

May 01

W3C Valid Buttons, A jQuery Approach

jQuery Script SolutionThere are many people who consider the W3C valid buttons as good indicators of a web designers’s understanding and attention to Web Standards. Although, this may not be entirely true, it is a reasonable and understandable way of thinking. Thus, almost every site built these days will display a valid link to the W3C’s validation app somewhere in the site (more often than not in the “footer” section). However, most designer will refrain from using the W3C provided valid buttons and will instead cook a textual or visual solution of their own. But wouldn’t it be nice if you could use these somewhat-iconic buttons only when needed? Wouldn’t it be nice if they were less obtrusive and had a place in your design? If these inquiries gave you a sense of excitement, take a look at the demo and read on.

A jQuery Approach

For those of you who are long time readers, it comes with no surprise that I have chosen jQuery for this tutorial. For those of you who are new, visit the jQuery homepage and prepare yourself to be amazed by this versatile and lightweight java framework.

There are two main problems with the W3c valid buttons, which prevent most designers from using them. Firstly, the color choices … rather, the lack of color choices for the buttons makes it hard for it to blend with any design. Secondly, unless the site being built is a W3C site, chances are the design will have a more 2.0 look. In other words, unless the design of your site is outdated, these buttons will clash with your current design.

My solution to these problems is rather simple (thanks to jQuery), hide the buttons unless needed. In other words, use jQuery to append the W3C button(s) to your validation link(s), position it above the link(s), and animate them. In order to have a better sense of this technique, take a look at the demo.

Ready To Use Script

If you wish to download the script, scroll to the end of this post and click on the download button. However, before you hurry away with a big smile in your face here are a few things you should know (AKA how-to):

  1. jQuery is needed for the script to work.
  2. You will need to add one of the following classes to your validation links:
    • valid_html
    • valid_xhtml
    • valid_css

Note: the .js file is set to work with the valid_xhtml and valid_css classes. If you wish to use the valid_html class instead of the valid_xhtml one, uncomment that line of code and viceversa. Also, if you are using this script with WordPress make sure to read my Using jQuery with Wordpress post.

Download & Copyright Things

The script is free for you to use, modify, or destroy (hopefully not the latter). But recognition or a link back is always well received. Please make sure to leave any thoughts or problems you have with the script. Enjoy!

Download Script