CSS Wizardry posts tagged ‘CSS’


Zebra-striping rows and columns

Zebra-striping tables is certainly not a new thing; it has been done and discussed for years. They (allegedly) aid usability in reading tabular data by offering the user a coloured means of separating and differentiating rows from one another. I say allegedly, there has been research into their effectiveness, conducted by Jessica Enders over at A List Apart which proved pretty inconclusive.

Striping a table’s alternate rows couldn’t be simpler. By programatically adding a class of odd or suchlike to every other <tr> you can then apply styles to this row (usually a pale background colour) and create zebra-stripes. An even better method would be to ditch the extraneous class and use the nth-of-type selector, thus:

tbody tr:nth-of-type(odd){
  background:rgba(255,255,136,0.5); /* Pale yellow with 50% opacity */
}

What the nth-of-type selector is doing here is looking for every odd <tr> in the <tbody>, that is to say the 1st, 3rd, 5th, 7th and so on.

By understanding this, we can apply that logic to create zebra-striped columns, too. Thus:

tbody td:nth-of-type(odd),
thead th:nth-of-type(odd){
  background:rgba(255,255,136,0.5);
}

Above: Here we target every other <th> in the <head>, and <td> in the <tbody>.

We can also combine the two, to create a table where every other row and every other column is striped simultaneously, and by using the rgba() colour declaration we can effectively layer the stripes, therefore showing where they cross over. The code for this simply combines the two:

tbody td:nth-of-type(odd),
tbody tr:nth-of-type(odd),
thead th:nth-of-type(odd){
  background:rgba(255,255,136,0.5);
}

You wanna see a demo?

Sure thing, here you go…

Addendum

After questions about browser support, I have decided to add a little onto the article…

The selectors involved here are only supported in CSS3 capable browser, that is to say pretty much anything but Internet Explorer. However, due to zebra-striping’s negligible benefits and inherently progressive nature, I don’t feel that it is a feature that is important enough to warrant full cross-browser support. Research shows that tables are just as usable without zebra-striping as with, therefore in IE et al, the user is not receiving a sub-par experience.

Of course if you do want to support Internet Explorer, you can always revert to programmatically adding an odd class to <tr>, <th> and <td> elements.


Building sites without using IDs or classes

This morning, for one reason or another, I decided to have a go at coding up a page without using any IDs or classes in my markup, and therefore none in my CSS. I’m not sure why I tried it, I guess I just did… In order to make it a fairly painless job I dove straight into the browser and coded up a simple header, footer, two column layout. View the demo and be sure to view the source.

(more…)


Multiple column lists using one <ul>

This is a quick, simple tutorial on how to create multiple column lists by only using one ul. Often is the case when you’d want multiple lists side-by-side, but you end up using markup like <ul class="col"> in order to get several lists sat next to each other. However, by simply floating lis left and setting their width to the correct percentage (two columns = li{width:50%;} and so on), you can attain a multiple column list pretty easily.

View demo

(more…)


iPhone CSS—tips for building iPhone websites

With the rapid rise in mobile browsers, it has probably never been more important to ensure your sites can be handled on these platforms. By far one of the most popular such browsers is Mobile Safari on the iPhone—this is one of the easiest browsers to develop for: it runs on Webkit (meaning a lot of rich CSS3 support) and it’s only ever on one resolution and on one OS.

N.B. This article addresses iPhone development and iPhone development only. There is no reason why you cannot or should not develop for other mobile devices and platforms, Apple or otherwise. This just happens to be an iPhone only post.

The practical upshot of this is that you need to do no cross-browser testing, and can use all the CSS3 you like. This post will show you some of the basics of developing and designing websites for the iPhone and Mobile Safari.

(more…)


Typographic work planner

No one likes being told what to do, especially if it’s work related, but nevertheless jobs need done. Why present boring stuff in a boring way? If you’re going to be told what to do, at least soften the blow by being told nicely. Enter this, a little HTML/CSS typographic work planner. By using some super-semantic HTML and a dash of CSS you can craft a beautiful looking yet incredibly simple work planner for you and your staff.

Screenshot of the typographic work planner

(more…)


Search CSS Wizardry

Archives

Categories

Twitter—2167 followers

You should follow me.

Subscribe—RSS