Dev.Opera - Follow the standards, break the rulesDev.Opera - Follow the standards, break the rules

Login

Lost password?

Forums » Article Discussions

Discuss the articles posted on Dev.Opera.

Note: You need to login to post in the forums. if you don't have an account you first need to sign up.

By teleject anchor Thursday, 28. August 2008, 13:12:43

Zebra striping tables with CSS3

In this article Christopher Schmitt gives a succinct overview of how to use the nth-child CSS3 property to easily create zebra-striped HTML tables.

( Read the article )

By floyd1616 anchor Sunday, 31. August 2008, 17:01:25

avatarHi all, Hi Christopher
also this article was translated in Italian: http://www.extrowebsite.com/articolocss.asp?id=81 :smile:

Giuseppe

By FataL anchor Monday, 1. September 2008, 05:44:27

avatarThe question is it possible to make nth-child to count only elements with some class name?
Now seems that the current algorithm is to gather pseudo-classes first...
This can be very usefull when you want to show and hide dynamically groups of rows in a table and want to keep proper "zebra styling" of rows.
tbody tr.zebra:nth-child(even) {background-color:Gray}
See examples here: http://rusrestaurant.com/tests/nth-child/nth-child-hidden.html

By brucelawson anchor Monday, 1. September 2008, 15:08:09

avatarHi FataL

interesting question, and I had to go to the engineering group within Opera to get an answer.

The behavior you document is correct although it feels unintuitive.

Selectors work on the DOM tree, not on the visual tree, so whether or not an item has a display property of none makes no difference to the calcualtion of selectors.

Post edited Monday, 1. September 2008, 15:43:36

By FataL anchor Monday, 1. September 2008, 16:46:38

avatarThanks for reply Bruce!

Selectors work on the DOM tree, not on the visual tree, so whether or not an item has a display property of none makes no difference to the calcualtion of selectors.

This is true. But I'm talking about different behaviour of nth-child.
Imagine (or look at my examples) that some of rows have class hideit and applied style like
.hideit {display:none}
(let's not talk about accessibility this time :wink: )
I would expect that this stylesheet rule will paint my table correctly -- taking to account rows w/o class.
tbody tr:not([class]):nth-child(even) {background-color:Gray}
This selector works only with DOM tree, looking for a class attribute befor applying nth-child.

I would like to propose this changes to CSS 3 selectors spec, but first I want to know if it's doable for browser vendor.

Post edited Monday, 1. September 2008, 16:52:30

By brucelawson anchor Tuesday, 2. September 2008, 15:57:51

avatarHi FataL
the response I got yesterday to your initial question was

"Selectors are designed to be invariant of CSS declarations. Also, Selectors is a standalone concept and can be used outside of CSS (eg, in XBL)"

It always evaluates the :nth-child first. Opera and Safari agree on that.

I made a test case to show some of my colleagues, and it was a nightmare to get our brains round. I agree with you that it's not the way a web author would expect it to work at all, particularly if you're used to CSS counters which are incremented with visibility:hiddenn, but not incremented if they take display:none'.

I'm going to write up a blog post for the Opera Developer Network blog before the end of the week detailing all this.

By FataL anchor Tuesday, 2. September 2008, 16:30:35

avatarOk, thank you very much for quick investigation. So I can't use CSS 3 selectors for painting dynamic tables and need to write some smart JS that will reapply classes on visible table rows every time user show/hide something...

CSS counters which are incremented with visibility:hiddenn, but not incremented if they take display:none'

Really? :eyes:
I should take a note about this somewhere. :smile:

By brucelawson anchor Wednesday, 3. September 2008, 07:42:04

avatarYeah, here's the item in the CSS 3 generated content spec
http://www.w3.org/TR/REC-CSS2/generate.html#q10 (which is, of course, still being developed and so is something of a moving target - see my blogpost on replacing images with the <code>content</code> property from the same CSS 3 module http://my.opera.com/ODIN/blog/css-3-image-replacement

Post edited Wednesday, 3. September 2008, 08:44:55

By FataL anchor Friday, 12. September 2008, 19:21:05

avatarAt least Opera should fix this:
http://www.quirksmode.org/css/nthchild.html

Opera has problems when elements are added dynamically.

By bugamok anchor Tuesday, 13. January 2009, 17:37:48

avatarGreat article!

/Peter

By FataL anchor Tuesday, 13. January 2009, 19:48:47

avatar

Originally posted by brucelawson:

I'm going to write up a blog post for the Opera Developer Network blog before the end of the week detailing all this.

Still impatiently waiting :smile:

Moderators: pepelsbey | dstorey | mcx | operadev | chrismills | shwetankdixit | brucelawson | iheni | andreasbovens | zibin | mollydotcom