Since Opera 9.5 started to support :last-child, I changed the markup/styling of the reports generated by my PNG batch processing utility. Finally the markup was down to an absolute minimum. There wasn't even a single extraneous character (except for new lines... for the bare minimum of legibility). I was really happy with the simplicity/elegance and lived happily ever after.
Well, not quite.
Two hours ago I did a checkout and after the tool processed the 2 new/changed files I took a look at the report. Instead of 682 rows there were now 684 rows, which happens to be just enough to trigger the bug on my machine. Firefox doesn't render the page in one go anymore, and whenever it stops elements which happen to be the last element right now get the :last-child rule applied. It stays this way even if the layout changes (e.g. by loading the rest or via JavaScript).
This means that you cannot rely on :first-child, :only-child, or :last-child. You only have good chances that they work with small test cases. With about 100kb of markup (or even 50kb if the site loads slow) they simply won't work reliable anymore. And things like :nth-child(), :nth-last-child(), :nth-of-type(), :nth-last-of-type(), :first-of-type, :last-of-type, :only-of-type etc. will be broken in a similar fashion once they are supported.
And if that wouldn't be bad enough already, this bug is very old:
Bug 254598 – Firefox 9.1 extend :first-child styling erratically (reported: 2004-08-06)
Which is a duplicate of:
Bug 73586 – matching of :first-child, :only-child, and :last-child not dynamically updated [SELECTORS-DYNAMIC] (reported: 2001-03-27)
2001? Are you kidding? If it would be another kind of mistake it would already go to elementary school by now.
At the time of writing the latest Firefox 3.0 builds show similar random behavior on all operating systems. Opera doesn't have that kind of issues. And IE... well, it doesn't support that kind of thing anyways. It will be really embarrassing if IE gets it right before Firefox does. Only 5-10 years left! Hurry up! :v
Comments
Gecko is in 1999 now!
Hey, at least they've fixed inline-blocks and hyphenation waiting since 1999! You must wait a few years till they get to these new fancy 2001 bugs! ;)
last-child
Are you sure last-child works correctly in Opera? I tested Firefox 2.0.0.10, Safari 3.0.4 (5523.10), a recent Webkit nightly and Opera 9.5b on the bugzilla test cases (machine is a Macbook 2GHz running OSX 10.5.1 Leopard)
For the :first-child case
For the :last-child case
Conclusions:
=> Don't use first-child or last-child when the page is scripted on elements where these values may dynamically change.
You're right
Opera 9.5b does indeed fail in that test. However, it's fine with static pages... even with big ones.
However, it's fine with
However, it's fine with static pages... even with big ones.
Yeah, sorry about that I noticed that you were specifically talking about static pages only after posting my comment.
Nah...
It's cool. I'm thankful for the clarification. It's really good to know about these issues. :)
Only first-child is CSS2
Of all of the selectors you guys have discussed, only first-child is a final specification (CSS2). The others are all CSS3, which is currently in working draft. So currently, Opera works completely right. But two things to remember: 1) a simple-to-describe bug isn't necessarily a simple-to-fix bug, and 2) if it was the other way around (Opera broken, Firefox working), you couldn't download the source, fix it yourself, and contribute the change.
Yes, in theory...
In theory one could download the FF source and fix it by him/herself, yes. But it's a rather deep glitch, which requires quite a lot of knowledge about the architecture. And then there is the requirement for rather good C/C++ skills and a hefty chunk of spare time.
Of course you also need to know about that bug in first place. If you take a look at the rather low amount of comments over at bugzilla, you can clearly tell that most developers aren't aware of it. Why should you search for such a bug, if :last-child works oh-so-nice? How could you guess that it won't work reliable outside of small demos and test cases?
It's sort of like a submarine bug. Reaching a critical mass of awareness will happen after these kind of pseudo class selectors are widely used at which point any further delay will be rather annoying.
It also doesn't matter if it's draft stuff or not. With the current architecture these things or similar things simply won't work as intended, because there are no events or similar hooks in place which could sort it out.
Since all my spare time slots are already in use for the foreseeable future (and since I don't intend to do any C/C++ ever again), the most logical course of action was to spread the word... or well, rant about it.
:no-child-left-behind, broken since 2002
:P
i'm going to hell lol
Never, never again
Haha, I love the "and since I never intend on using C/C++ ever again".
I tried learning, but I can accomplish the same thing in python in 30 lines of code, rather than 50-60 in C++.
Say never "never"
I actually wrote a little bit of C++ after writing that and I'll probably write another 100 lines, but that's about it. 200 lines a year is already too much of that error prone stuff. ;)
Post new comment