Creative Web Specialist - An online portfolio and resource site of Warren Buckley

Latest Posts

May24th

Alternative table row styling with CSS and Javascript

Author
Warren Buckley
Categories

Hello all,

This blog post is for my own reference mainly for a technique I have read and learnt about. What I was looking for was to be able to style alternative rows a different colour, similar to the popular layout of iTunes where the row colour alternates between dark and light blue.

I wanted to be able to achieve this affect easily without having to add Classes to my table for each different row manually, I wanted this to be automatic so it can be used in CMS systems without the end user having to ammend the HTML code on the table. I know that in the future we will not have to use JavaScript to help us do this as the new CSS3 selectors will allow us to do this.

This is the CSS rule that will be used in the future and will obviously style all odd table rows with the background colour red.

tr:nth-child(odd)
{
background-color:red;

}

Before we go any further, lets view the example of a table with alternative row colours with the use of JavaScript and CSS

Now you have seen the example, feel free to view the source of the page and learn from it - however I cannot take credit for the work, as this was something I found on another blog.

I will edit this post in the next few days when I fully understand the JavaScript and how it is functioning so I can try and explain it - so watch this space.

0 comments
Post a comment »

Comment's have been disabled, due to getting hit badly with comment form spam

My Skill Set

This is a quick list of my skill set to date

  • XHTML
  • CSS
  • Photoshop (Slicing)
  • XSLT
  • ASP.NET
  • Umbraco .NET CMS

My del.icio.us

My Last.FM

I am listening to:

  • Ain't Pretending by CowbellOh Girl29 Jul 2010, 10:37
  • Just Want Your Love by CowbellOh Girl29 Jul 2010, 10:33
  • Oh Girl by CowbellOh Girl29 Jul 2010, 10:31
Warren Buckley is an umbraco MVP 2008/2009 Warren Buckley is an umbraco level 1 certified developer

Photo of Warren Buckley Warren Buckley is a Creative Web Specialist based in Leigh on Sea, Essex , UK.