use*_*812 -2 css css-selectors css3
I have some questions on the capabilities of CSS 2 and CSS 3 selectors.
Are CSS 2 selectors powerful enough to select any element in a DOM tree?
Is there anything that CSS 3 selectors could do while CSS 2 selectors could not?
Could any CSS 3 selector be theoretically converted to a CSS 2 selector (although the converted CSS 2 selector may be a bit tedious)?
Is there any tool for converting CSS 3 to CSS 2 selectors?
I ask this question as I find that there is a good CSS 3 selector generator (e.g. superselector) but there are tools that know only CSS 2.
No, otherwise why would there be a level 3? Unless you're asking about something like the * selector, which does match any element in the document, and didn't exist prior to CSS2.
If you're asking whether you can construct selectors to match elements for any sort of condition, again the answer is no. Pseudo-classes, for example, represent abstractions of the document tree that can't be expressed with other simple selectors, but CSS2 comes with a very limited selection of pseudo-classes that may be used, which certainly don't represent all possible conditions you may have in mind. Most of level 3 consists of new pseudo-classes to address precisely this, but again, they don't account for all possible scenarios.
Yes. See above.
Only some of them, but not all, again for obvious reasons.
For example, div:nth-child(4) can be replicated using :first-child and the appropriate number of next-sibling selectors:
:first-child + * + * + div
Run Code Online (Sandbox Code Playgroud)
See my answer to this question for details.
However you cannot replicate any of the substring-matching attribute selectors introduced in Selectors 3 with the ones in CSS2. You also cannot replicate :nth-child() with formulas such as :nth-child(2n+1) using CSS2 selectors, nor can you completely replicate :nth-of-type() without making any assumptions about the DOM. Just to name a few examples.
I cannot answer this, but someone might have tried making a converter and failed for the reason I've given above.