Sunday 1 July 2012

CSS 3 selectors


In September and October of 2005 I published a series of articles that explained the selectors that are available in CSS 2.1. A quick summary is that most of the selectors described in those articles can be used now in modern browsers like Mozilla/Firefox, Safari, and Opera. We just need to wait for Internet Explorer to catch up before we can start using the full power of CSS 2.1 selectors. The good news is that Internet Explorer will catch up, at least to some extent, with the release of version 7.
If we look a little further ahead, there are even more powerful selectors waiting to be implemented and used in CSS 3. Many of the CSS 3 selectors have already been implemented in modern browsers, but in general support is far too patchy for developers to rely on these new selectors. However, there are cases where they can be used to add nice forward enhancing features, so I think taking a look at how the new selectors in CSS 3 work can be useful.
In this article, the specification I am referring to is the Selectors W3C Working Draft 15 December 2005. The new selectors described in the document will be used by CSS level 3, but may also be used by other languages. If you are reading this article months, or even years after that date it may be worth checking if a more recent version is available.
I am not going to explain the basics of how CSS selectors in general work here. If you need a refresher, a good place to start is CSS 2.1 selectors, Part 1.
First, a quick overview of the selectors that are new in CSS 3:
Overview of CSS 3 selector syntax
Selector type Pattern Description
Substring matching attribute selector E[att^=”val”] Matches any E element whose att attribute value begins with “val”.
Substring matching attribute selector E[att$=”val”] Matches any E element whose att attribute value ends with “val”.
Substring matching attribute selector E[att*=”val”] Matches any E element whose att attribute value contains the substring “val”.
Structural pseudo-class E:root Matches the document’s root element. In HTML, the root element is always the HTML element.
Structural pseudo-class E:nth-child(n) Matches any E element that is the n-th child of its parent.
Structural pseudo-class E:nth-last-child(n) Matches any E element that is the n-th child of its parent, counting from the last child.
Structural pseudo-class E:nth-of-type(n) Matches any E element that is the n-th sibling of its type.
Structural pseudo-class E:nth-last-of-type(n) Matches any E element that is the n-th sibling of its type, counting from the last sibling.
Structural pseudo-class E:last-child Matches any E element that is the last child of its parent.
Structural pseudo-class E:first-of-type Matches any E element that is the first sibling of its type.
Structural pseudo-class E:last-of-type Matches any E element that is the last sibling of its type.
Structural pseudo-class E:only-child Matches any E element that is the only child of its parent.
Structural pseudo-class E:only-of-type Matches any E element that is the only sibling of its type.
Structural pseudo-class E:empty Matches any E element that has no children (including text nodes).
Target pseudo-class E:target Matches an E element that is the target of the referring URL.
UI element states pseudo-class E:enabled Matches any user interface element (form control) E that is enabled.
UI element states pseudo-class E:disabled Matches any user interface element (form control) E that is disabled.
UI element states pseudo-class E:checked Matches any user interface element (form control) E that is checked.
UI element fragments pseudo-element E::selection Matches the portion of an element E that is currently selected or highlighted by the user.
Negation pseudo-class E:not(s) Matches any E element that does not match the simple selector s.
General sibling combinator E ~ F Matches any F element that is preceded by an E element.
If all that doesn’t make much sense right now, don’t worry. Each selector will be described in more detail in this article, and there are examples of how each selector can be used.

Substring matching attribute selectors

This whole group of selectors is new, and the selectors in it let developers match substrings in the value of an attribute.
Assume that you have an HTML document that contains the following markup structure:
  1. <div id="nav-primary"></div>
  2. <div id="content-primary"></div>
  3. <div id="content-secondary"></div>
  4. <div id="tertiary-content"></div>
  5. <div id="nav-secondary"></div>
By using the substring matching attribute selectors you can target combinations of these structural parts of the document.
The following rule will set the background colour of all div elements whose id begins with “nav”:
  1. div[id^="nav"] { background:#ff0; }
In this case the selector will match div#nav-primary and div#nav-secondary.
To target the div elements whose id ends with “primary”, you could use the following rule:
  1. div[id$="primary"] { background:#ff0; }
This time the selector will match div#nav-primary and div#content-primary.
The following rule will apply to all div elements whose id contain the substring “content”:
  1. div[id*="content"] { background:#ff0; }
The elements that will be affected by this rule are div#content-primary, div#content-secondary, and div#tertiary-content.
The substring matching attribute selectors are all fully supported by the latest versions of Mozilla, Firefox, Flock, Camino, Safari, OmniWeb, and Opera, so if it wasn’t for Internet Explorer we could start using them now.

The :target pseudo-class

URLs with fragment identifiers (an octothorpe, “#”, followed by an anchor name or element id) link to a certain element within the document. The element being linked to is the target element, and the :target pseudo-class makes it possible to style that element. If the current URL has no fragment identifier, the :target pseudo-class does not match any element.
Assuming the HTML structure mentioned earlier in this document, the following rule would put an outline around div#content-primary when the URL contains that fragment identifier:
  1. div#content-primary:target { outline:1px solid #300; }
An example of such an URL is http://www.example.com/index.html#content-primary.
The :target pseudo-class is currently supported by browsers based on Mozilla and Safari.

UI element states pseudo-classes

The :enabled and :disabled pseudo-classes

The :enabled and :disabled pseudo-classes allow developers to specify the appearance of user interface elements (form controls) that are enabled or disabled, provided that the browser allows styling of form controls. The following rules will apply different background colours to single line text inputs depending on whether they are enabled or disabled:
  1. input[type="text"]:enabled { background:#ffc; }
  2. input[type="text"]:disabled { background:#ddd; }

The :checked pseudo-class

The :checked pseudo-class allows developers to specify the appearance of checked radio and checkbox elements. Again, this is provided that the browser allows styling of form controls. This CSS rule will apply a green border to checked radio and checkbox elements:
  1. input:checked { border:1px solid #090; }
The UI element states pseudo-classes are currently supported by Opera and browsers based on Mozilla.
Note that many web browsers restrict how much the appearance of form controls can be changed by web developers. More on that subject is available in my articles Styling form controls and Styling even more form controls.

Structural pseudo-classes

The structural pseudo-classes allow developers to target elements based on information that is available in the document tree but cannot be matched by other simple selectors or combinators. The structural pseudo-classes are very powerful, but unfortunately current browsers only support a few of them.

The :root pseudo-class

The :root pseudo-class targets the document’s root element. In HTML, the root element is always the HTML element, which means that the following two rules are the same (well, almost - :root has a higher specificity than html):
  1. :root { background:#ff0; }
  2. html { background:#ff0; }
The :root pseudo-class is currently supported by browsers based on Mozilla and Safari.

The :nth-child() pseudo-class

The :nth-child() pseudo-class targets an element that has a certain number of siblings before it in the document tree. This argument, which is placed within the parentheses, can be a number, a keyword, or a formula.
A number b matches the b-th child. The following rule applies to all p elements that are the third child of their parent element:
  1. p:nth-child(3) { color:#f00; }
The keywords odd and even can be used to match child elements whose index is odd or even. The index of an element’s first child is 1, so this rule will match any p element that is the first, third, fifth, and so on, child of its parent element:
  1. p:nth-child(odd) { color:#f00; }
The following rule matches p elements that are the second, fourth, sixth, and so on, child of their parent element:
  1. p:nth-child(even) { color:#f00; }
The formula an + b can be used to create more complex repeating patterns. In the formula, a represents a cycle size, n is a counter starting at 0, and b represents an offset value. All values are integers. Understanding how this works is easier when you look at a few code examples, so let’s do that.
The following rules will match all p elements whose index is a multiple of 3. In the first rule, b is zero and could have been omitted, as in the second rule:
  1. p:nth-child(3n+0) { color:#f00; }
  2. p:nth-child(3n) { color:#f00; }
The offset value can be used to define at which child a repeating rule starts to apply. If you have a data table with 20 rows and want every odd row after the tenth row to have a different background colour, you can use this rule:
  1. tr:nth-child(2n+11) { background:#ff0; }
Since n starts at 0, the first tr element to be affected is the 11th. Next is the 13th, then the 15th, and so on.
More details are available in the :nth-child() pseudo-class section of the CSS 3 Selectors specification.
So, what about browser support for this very useful selector? Not good at all. As far as I can tell, no browser supports this or any of the other “nth” selectors. Please correct me if you know otherwise.

The :nth-last-child() pseudo-class

The :nth-last-child() pseudo-class works just like the :nth-child() pseudo-class, except that it targets an element that has a certain number of siblings after it in the document tree. In other words, it starts counting from the last child instead of the first, and counts backwards. The following rule will match the second-to-last tr element of a table:
  1. tr:nth-last-child(2) { background:#ff0; }
The :nth-last-child() pseudo-class is currently not supported by any browsers.

The :nth-of-type() pseudo-class

The :nth-of-type() pseudo-class works exactly like the :nth-child() pseudo-class, but only counts those elements that are of the same type as the element the rule is applied to. This rule will match every p element that is the third p element of its parent:
  1. p:nth-of-type(3) { background:#ff0; }
This can be useful if you want to make sure that you are really targeting the third p element. At first you might think that you could just as well use the nth-child pseudo-class, but :nth-child(3) will take all sibling elements into account, so the result will be different unless all p elements only have siblings that are also p elements.
The :nth-of-type() pseudo-class is currently not supported by any browsers.

The :nth-last-of-type() pseudo-class

The :nth-last-of-type() pseudo-class targets an element that has a certain number of siblings of the same element type after it in the document tree. Just like the :nth-last-child() pseudo-class, it starts counting from the last child instead of the first, and counts backwards. The following rule will match each second-to-last sibling of type p:
  1. p:nth-last-of-type(2) { background:#ff0; }
The :nth-last-of-type() pseudo-class is currently not supported by any browsers.

The :last-child pseudo-class

The :last-child pseudo-class targets an element that is the last child of its parent element. It is the same as :nth-last-child(1). This rule will match all p elements that are the last child of their parent element:
  1. p:last-child { background:#ff0; }
The :last-child pseudo-class works in browsers based on Mozilla. It is not supported by Opera and is buggy in Safari (the above rule matches all p elements in the document). Surprisingly it works as expected in OmniWeb (tested in version 5.1.1), despite that browser being based on Safari. That could be caused by a regression in the latest version of Apple WebKit, since OmniWeb is usually built on a slightly older version of WebKit than what Safari is using.

The :first-of-type pseudo-class

The :first-of-type pseudo-class targets an element that is the first sibling of its type. it is the same as :nth-of-type(1).
  1. p:first-of-type { background:#ff0; }
The :first-of-type pseudo-class is currently not supported by any browsers.

The :last-of-type pseudo-class

The :last-of-type pseudo-class targets an element that is the last sibling of its type. it is the same as :nth-last-of-type(1).
  1. p:last-of-type { background:#ff0; }
The :last-of-type pseudo-class is currently not supported by any browsers.

The :only-child pseudo-class

The :only-child pseudo-class targets an element whose parent element has no other element children. It is the same (but with a lower specificity) as :first-child:last-child or :nth-child(1):nth-last-child(1).
  1. p:only-child { background:#ff0; }
The :only-child pseudo-class works in browsers based on Mozilla. Safari seems to interpret it as :first-child (the above rule matches all p elements in the document that are the first child of their parent element).

The :only-of-type pseudo-class

The :only-of-type pseudo-class targets an element whose parent element has no other children of the same element type. It is the same (but with a lower specificity) as :first-of-type:last-of-type or :nth-of-type(1):nth-last-of-type(1).
  1. p:only-of-type { background:#ff0; }
The :only-of-type pseudo-class is currently not supported by any browsers.

The :empty pseudo-class

The :empty pseudo-class targets an element that has no children. That includes text nodes, so of the following elements, only the first is empty:
  1. <p></p>
  2. <p>Text</p>
  3. <p><em></em></p>
The following CSS rule will match that first element:
  1. p:empty { background:#ff0; }
The :empty pseudo-class is currently supported by browsers based on Mozilla. Safari erroneously applies the rule to all elements of the given element type.

The negation pseudo-class

The negation pseudo-class, written :not(s), takes a simple selector as an argument. It targets elements that are not targeted by the simple selector. For example, the following CSS will target any element that is not a p element:
  1. :not(p) { border:1px solid #ccc; }
The negation pseudo-class currently works in browsers based on Mozilla and Safari.

The ::selection pseudo-element

The ::selection pseudo-element matches the portion of an element that is currently selected or highlighted by the user. One possible use for this would be to control the appearance of selected text.
Only a few CSS properties apply to ::selection pseudo-elements: color, background, cursor, and outline.
The following rule will make the foreground colour of a selection red:
  1. ::selection { color:#f00; }
The ::selection pseudo-element currently only works in browsers based on Safari. The behaviour is a bit unpredictable, so the Safari implementation needs a bit of improvement. Mozilla based browsers support it if you use a -moz- prefix: ::-moz-selection. The prefix will probably be removed eventually.

The General sibling combinator

The general sibling combinator consists of two simple selectors separated by a “tilde” (~) character. It matches occurrences of elements matched by the second simple selector that are preceded by an element matched by the first simple selector. Both elements must have the same parent, but the second element does not have to be immediately preceded by the first element. This CSS rule will target ul elements that are preceded by a p element with the same parent:
  1. p ~ ul { background:#ff0; }
The general sibling combinator is currently supported by Opera and browsers based on Mozilla.

Better browser support wanted

Some CSS 3 selectors are widely supported. Unfortunately, some of the most useful selectors are either not supported at all or have very limited support in current browsers. That makes many of the selectors described in this article more or less useless on today’s web. Don’t be afraid to experiment though. You can still use those that are supported to provide forward enhancement to advanced browsers.
So, which browser do you think will be the first to support most or all CSS 3 selectors? Safari, Firefox, or Opera? Or maybe even Internet Explorer?

Using CSS Border-image

Border-image: using images for your border

Another exciting new border feature of CSS3 is the property border-image. With this feature you can define an image to be used instead of the normal border of an element. This feature is actually split up into a couple of properties: border-image and border-corner-image. These two values are shorthands for:
  • border-image:
    • border-top-image
    • border-right-image
    • border-bottom-image
    • border-left-image
  • border-corner-image:
    • border-top-left-image
    • border-top-right-image
    • border-bottom-left-image
    • border-bottom-right-image
border-image currently works in Safari and Firefox 3.1 (Alpha). The syntax to use it is:
border-image: url(border.png) 27 27 27 27 round round;
Which results in:
Lorem ipsum dolor sit amet.
Or:
border-image: url(border.png) 27 27 27 27 stretch stretch;
Which then results in:
Lorem ipsum dolor sit amet.
For those of you not so lucky as to be able to see this, here are screenshots of the two examples.
Number one:
border-image first example
Number two:
border-image second example

Tuesday 5 June 2012

Top 10 CSS in HTML Table Designs


First things first

We start with a valid xhtml 1.0 strict markup. Here is an example of a valid table markup:
01<!-- Table markup-->
02
03<table id="...">
04
05    <!-- Table header -->
06
07        <thead>
08            <tr>
09                <th scope="col" id="...">...</th>
10                ...
11            </tr>
12        </thead>
13
14    <!-- Table footer -->
15
16        <tfoot>
17            <tr>
18                  <td>...</td>
19            </tr>
20        </tfoot>
21
22    <!-- Table body -->
23
24        <tbody>
25            <tr>
26                <td>...</td>
27                ...
28            </tr>
29            ...
30        </tbody>
31
32</table>
You can read more about xhtml table markup in HTML Dog’s Table Section. I have tested the tables below in Mozilla Firefox 3, IE 6 and 7, Opera 9.x and Safari. Also note that I apply a light blue color scheme to all of these tables to give the article a consistent look. You can modify the color scheme to match your site — the source package is provided in the end of the article.
Before we start, let’s review the general rule of thumb for styling of tables:
  1. Tables love space. Set the width of tables carefully, according to the content. If you don’t know the perfect width, simply set the width of thetable to 100%. Tables look nicer when they have “overwidth”, and when it comes to tables too much width is definitely better than too little width.
  2. Cells need some padding. Sure, each table cell relates to each other. But it doesn’t mean that we have to pull them too close, right? Define some space between the cells, crammed up table cells are so much harder to read.
  3. Treat tables the way you treat content. Tables are read similarly to the way we read text — except it’s harder and it takes more time to read a table. So be careful with the amount of contrast you are giving to your table. Use soft colors — it’s easier for the eyes. Don’t treat your table like it’s a graphical decoration. Make sure that the style you apply to it makes the content more readable, not the other way around.
Now that we are all set up let’s get going, shall we?

1. Horizontal Minimalist

Horizontal tables are tables that are read rather horizontally than vertically. Each entity is represented by a row. You can style these types of tables with minimalist style. Simply set enough padding to the cells (td and th) and put a 2 pixel border underneath the header.
EmployeeSalaryBonusSupervisor
Stephen C. Cox$300$50Bob
Josephin Tan$150-Annie
Joyce Ming$200$35Andy
James A. Pentel$175$25Annie
Because horizontal tables are supposed to be scanned horizontally, clearing the border of the table increases the efficiency of the table. The lack of border, however, makes this table design hard to read if it has too many rows. To counter it we simply add 1 pixel border underneath all td elements:
EmployeeSalaryBonusSupervisor
Stephen C. Cox$300$50Bob
Josephin Tan$150-Annie
Joyce Ming$200$35Andy
James A. Pentel$175$25Annie
The tr:hover rules are very useful to aid people reading a minimally designed tables. When the mouse cursor hovers over a cell, the rest of the cells in the same row highlights immediately, making it easier to track things if your tables have multiple columns.
Important!
Carefully finetune the typography and the padding between the cells
Pros
Very easy to style, good for simple tables
Cons
tr:hover rules don’t work in IE 6, table can be confusing if it has too many columns
Play with
Color scheme, typography, tr:hover effects

2. Vertical Minimalist

Although rarely used, vertically oriented tables are useful for categorizing or comparing descriptions of objects, with each entity represented by a column. We can style it in minimalistic style by adding whitespace separators between columns.
ComedyAdventureActionChildren
Scary MovieIndiana JonesThe PunisherWall-E
Epic MovieStar WarsBad BoysMadagascar
SpartanLOTRDie HardFinding Nemo
Dr. DolittleThe Mummy300A Bug’s Life
Add large border-left and border-right with the same color as background. You can use transparent borders if you want, but IE 6 screws it all up. Since this table is supposed to be read from top to bottom (vertically), adding tr:hoverdoes not help and instead makes it harder to read the data. There is perhaps a Javascript-based solution which enables you to highlight the whole column when a mouseover event occurs, but that’s beyond the scope of this article.
Important!
Carefully finetune the typography and the padding between the cells, do not add tr:hover effect
Pros
Easy to style, good for simple tables
Cons
Can not be used if background is not a solid block of color, suitable only for some tables
Play With
Color scheme and typography

3. Box

The most dependable of all styles, the box style works for all kinds of tables. Pick a good color scheme and then distribute background-color to all the cells. Don’t forget to accentuate the differences of each cell by defining border as a separator. An example of a box style table is the following table:
EmployeeSalaryBonusSupervisor
Stephen C. Cox$300$50Bob
Josephin Tan$150-Annie
Joyce Ming$200$35Andy
James A. Pentel$175$25Annie
ComedyAdventureActionChildren
Scary MovieIndiana JonesThe PunisherWall-E
Epic MovieStar WarsBad BoysMadagascar
SpartanLOTRDie HardFinding Nemo
Dr. DolittleThe Mummy300A Bug’s Life
This style is nowadays probably the most used style. The tricky part is actually trying to find the color scheme that matches with your site. If your site is heavy on graphics, it will be pretty hard to use this style.
Important!
Choose a color scheme that matches with your site
Pros
Easy to style, flexible for large or small tables
Cons
Choosing the perfect color scheme could be tricky
Play with
Colors and borders, use dashed or dotted to achieve cute effects, typography, icons

4. Horizontal Zebra

Zebra-tables are pretty attractive and usable. The alternating background color can serve as a visual cue for people when scanning the table. To style a table as zebra, simply put a class="odd" to every odd ordered tr tag and define a style for it (e.g. using if ($count % 2) then even class else odd class in PHP).
01...
02
03    <tr class="odd">
04       <td>...</td>
05       ...
06    </tr>
07
08    <tr>
09       <td>...</td>
10       ...
11    </tr>
12
13...
EmployeeSalaryBonusSupervisor
Stephen C. Cox$300$50Bob
Josephin Tan$150-Annie
Joyce Ming$200$35Andy
James A. Pentel$175$25Annie
Important!
Do not put too much contrast on the zebra colors, you can blind your users
Pros
The zebra pattern can help people to scan the table
Cons
Adding class="odd" manually can be very tedious for large tables, many content management systems do not provide even/odd features on a table loop, hence picking the color scheme may be tricky
Play With
Contrasting color, borders, typography, icons

5. Vertical Zebra Style

Vertical zebra is easier to style than the horizontal one, as we can make use ofcolgroup and col elements to distribute column classes. However, the markup becomes a little bit heavier:
01<table>
02
03        <!-- Colgroup -->
04       <colgroup>
05          <col class="vzebra-odd">
06          <col class="vzebra-even">
07          <col class="vzebra-odd">
08          <col class="vzebra-even">
09       </colgroup>
10
11        <!-- Table header -->
12       <thead>
13          <tr>
14             <th scope="col" id="vzebra-comedy">Employee</th>
15             ...
16          </tr>
17       </thead>
18
19       ...
20</table>
The colgroup element actually applies a style or class to the table, columnwise. Instead of tediously applying class for the first td or th element, we can use a more convenient colgroup-tag. For more information about colgroup visit this page.
ComedyAdventureActionChildren
Scary MovieIndiana JonesThe PunisherWall-E
Epic MovieStar WarsBad BoysMadagascar
SpartanLOTRDie HardFinding Nemo
Dr. DolittleThe Mummy300A Bug’s Life
Although perhaps more suitable for vertically-oriented table, this zebra-style can also be used for any other kind of tables.
Important!
Do not put too much contrast on the zebra colors, you can blind your viewer
Pros
Suitable for all types of tables
Cons
Choosing the color scheme could be tricky, need to add colgroup elements
Play With
Contrasting color, borders, colgroup and col, icons and typography

6. One Column Emphasis

In some tables, some particular column may have a higher weight than the other columns. If that’s the case, you can use colgroup and col to make that particular column stand out. In the example below, the first column serves as the starting point to read, so it is emphasized, just like we emphasize the first letter of the paragraph as drop caps:
CompanyQ1Q2Q3Q4
Microsoft20.330.523.540.3
Google50.240.6345.2339.3
Apple25.430.233.336.7
IBM20.415.622.329.3
You can also use one-column-emphasis-technique to highlight something important, say the column containing totals of an accounting table, or in a comparison table — for computer specification perhaps, the winning entity (column).
Important!
Be careful, don’t overdo the emphasis or the column will jump out, distracting the effort to read the rest of the columns.
Pros
Very effective when used in certain kind of tables
Cons
The necessary tr:hover effect does not work in IE, suitable for certain types of tables only
Play with
Color scheme, typography, icons and tr:hover effects

7. Newspaper

To achieve the so-called newspaper effect, apply border to table element and play with the cells inside. A quick, minimalistic newspaper style can look like this:
CompanyQ1Q2Q3Q4
Microsoft20.330.523.540.3
Google50.240.6345.2339.3
Apple25.430.233.336.7
IBM20.415.622.329.3
Simply play with color scheme, borders, padding, backgrounds, and tr:hovereffects of the cells (td and th). Other alternatives are presented below:
CompanyQ1Q2Q3Q4
The above data were fictional and made up, please do not sue me
Microsoft20.330.523.540.3
Google50.240.6345.2339.3
Apple25.430.233.336.7
IBM20.415.622.329.3
FAVORITEGREATNICEBAD
Passion of the ChristBourne UltimatumShoot ‘Em UpAli
The Big FishThe MummyApocalyptoMonster
Shawshank RedemptionCold MountainIndiana JonesDead or Alive
Greatest Story Ever ToldI Am LegendStar WarsSaw 3
Important!
Be careful with border-collapse, do not lose the signature border around the table!
Pros
Gives a royal, authorative aura to a table
Cons
Unsuitable for large tables (it loses it’s charm on large tables)
Play With
Typography, color scheme, background, border, padding, and tr:hover effects

8. Rounded Corner

Rounded corners are slick and modern, and it’s easy to apply it to a table, although you need to fire up Photoshop for this. Create images for all four corners of your table. Theoretically, we can make use of the nesting tr and td-elements to place the left and right corners of the table without adding additional markup. Unfortunately, IE 6 goes berserk and the table appears ugly, so the most stable way to do this is to put ID or class to all four corner cells of the table. Please consider the example below:
CompanyQ1Q2Q3Q4
The above data were fictional and made up, please do not sue me
Microsoft20.330.523.540.3
Google50.240.6345.2339.3
Apple25.430.233.336.7
IBM20.415.622.329.3
Pros
Great if you want untraditional table, probably the only viable option you have if your website uses rounded corners heavily
Cons
Takes longer to style, requires images
Play With
Color scheme, corner variations, typography, tr:hover effects, icons

9. Table Background

If you are looking for a quick and unique way to style your table, simply pick an attractive image or photo related to the subject of your table and set it to be thebackground-image of the table. You can add 50% grey png-image asbackground-image of the cells to improve readability, and that means that you need a CSS-hack to make it work in IE 6:
1* html table tbody td
2{
3
4          /* IE CSS Filter Hack goes here*/
5
6}
The table would look like this:
EmployeeDivisionSuggestions
IE 6 users won’t see the transparent background if the hack is not applied
Stephen C. CoxMarketingMake discount offers
Josephin TanAdvertisingGive bonuses
Joyce MingMarketingNew designs
James A. PentelMarketingBetter Packaging
Important!
Make sure the image is relevant to the table’s contents
Pros
Very easy to style, delivers unique look, if used correctly the image can serve as a symbol that gives outstanding impression on the viewer
Cons
Needs hack to get the background work in IE 6, needs images
Play With
Background images, transparent PNGs, typography, colors, icons

10. Cell Background

You can apply background-image to the cells and achieve a consistent look. Say you have at least half an hour to spare and you want something that’s not too bland. Start your Photoshop and make 1 pixel width gradients, and set them asbackground-image of all cells. You’ll end up with a gradient style table:
EmployeeDivisionSuggestionsRating
Give background color to the table cells to achieve seamless transition
Stephen C. CoxMarketingMake discount offers3/10
Josephin TanAdvertisingGive bonuses5/10
Joyce MingMarketingNew designs8/10
James A. PentelMarketingBetter Packaging8/10
Similarly, pick a pattern and set it as background-image and you’ll end up with a pattern-styled-table:
EmployeeSalaryBonusSupervisor
Stephen C. Cox$300$50Bob
Josephin Tan$150-Annie
Joyce Ming$200$35Andy
James A. Pentel$175$25Annie
NationCapitalLanguageUnique
JapanTokyoJapaneseKarate
South KoreaSeoulKoreanGinseng
ChinaBeijingMandarinKung-Fu
IndonesiaJakartaIndonesianBatik
Important!
Make sure the text stands out against the background
Pros
Easy to style, not too bland
Cons
Uses images, patterns and gradients might distract reading
Play With
Color scheme, patterns, typography, borders, backgrounds, gradients, icons

Final Words

I know I barely scratched the surface with this article, so grab the source and play around. Feel free to post your favourite table designs, especially if it’s something I missed out. Over to you.