3 ms·
Here’s a thing I can’t do with CSS combinators, and I’ve always been curious why: apply rules to an element that contains any elements matching the criteria. E.
by derefr 8y ago
Here’s a thing I can’t do with CSS combinators, and I’ve always been curious why: apply rules to an element that contains any elements matching the criteria. E.g. (hypothetical Regex-like syntax):
(tr) > td img.emoji { padding-bottom: 1em; }
...would take any table row containing a cell with an image in it, and pad the table row itself a bit more, so as to balance out the image which is slightly larger than the text height.
The lack of this feature doesn’t bother me so much when actually developing for the web, but so many web scraping libraries offer CSS-selector accessors as an alternative to/replacement for XPath accessors, and when using these libraries, the need to grab the container element of the thing tagged with something (where the container itself has no distinguishing features other than having such a child) always results in inefficient spaghetti compared to what could potentially be a very simple selector.
Anyone know why we don’t have these? Something to do with the cost of rescans on DOM changes, maybe?
- s3m4j 8y agoGenerally you could do something like `select(identifier).parentNode` ? pseudo language because I'm tired
- recursive 8y agoThis has been requested many times. The short answer is performance implications. https://css-tricks.com/parent-selectors-in-css/ https://css-tricks.com/parent-selectors-in-css/
- hjnilsson 8y agoThis is because the CSS spec is consciously written so that you only never need to look forward when parsing the DOM. For the same reason there is no follow sibling selector, only previous sibling (`~`) This is a major performance factor, since it means all layout can be done in one pass. If the proposed selector were added. CSS layout would have unbounded complexity.