4 ms·
Webkit source: http://trac.webkit.org/browser/trunk/Source/WebCore/css/CSSSelector.cpp?rev=81845#L63 http://trac.webkit.org/browser/trunk/Source/WebCore/css/CSS
by bingaling 14y ago
Webkit source:
http://trac.webkit.org/browser/trunk/Source/WebCore/css/CSSSelector.cpp?rev=81845#L63 http://trac.webkit.org/browser/trunk/Source/WebCore/css/CSSS...
Specifically:
69 case Id:
70 s += 0x10000;
73 case Class:
88 s += 0x100;
id selectors are worth (0x10000/0x100) == 0x100 == 256 class selectors.
This seems to be the mozilla source:
http://hg.mozilla.org/mozilla-central/file/17c65d32c7b8/layout/style/StyleRule.cpp#l521 http://hg.mozilla.org/mozilla-central/file/17c65d32c7b8/layo...
521 nsAtomList* list = mIDList;
522 while (nsnull != list) {
523 weight += 0x010000;
524 list = list->mNext;
525 }
526 list = mClassList;
527 while (nsnull != list) {
528 weight += 0x000100;
529 list = list->mNext;
530 }
Same weights, Id = 0x10000, Class = 0x100
- CamperBob2 14y agoDid they mean to fall through to case Class in line 73?
- tlb 14y agoHe elided some lines, there is a break.
- deleted 14y ago[deleted]
- dclowd9901 14y agoFor some reason, based on the w3 documentation, I was under the impression that an id had an order of magnitude more specificity than a class. http://www.w3.org/TR/CSS2/cascade.html#specificity http://www.w3.org/TR/CSS2/cascade.html#specificity
- bingaling 14y agoI think it has _2_ (base 10) orders of magnitude more specificity. That's 10 times more specificity (than a single order)!
- sirclueless 14y agoOne might even say it has an order of magnitude more specificity than a single order.
- bodhi 14y agoFrom that spec: > Concatenating the four numbers a-b-c-d (in a number system with a large base) gives the specificity. So webkit is using 256 as "a large base". I only just read this spec a few months ago. For years I was under the impression that the spec was "1 point for an element, 5 for a class, 10 for an id", and the selector with the highest point value won...