3

Learning CSS i came across this document: How Browsers Work: Behind the scenes of modern web browsers Regarding to style sharing it states the following:

Sharing style data

WebKit nodes references style objects (RenderStyle) These objects can be shared by nodes in some conditions. The nodes are siblings or cousins and:

  1. The elements must be in the same mouse state (e.g., one can't be in :hover while the other isn't).
  2. Neither element should have an id
  3. The tag names should match
  4. The class attributes should match
  5. The set of mapped attributes must be identical
  6. The link states must match
  7. The focus states must match
  8. Neither element should be affected by attribute selectors, where affected is defined as having any selector match that uses an attribute selector in any position within the selector at all
  9. There must be no inline style attribute on the elements
  10. There must be no sibling selectors in use at all. WebCore simply throws a global switch when any sibling selector is encountered and disables style sharing for the entire document when they are present. This includes the + selector and selectors like :first-child and :last-child.

What is particularly interesting is the 10th rule stating any single sibling selector in the entire document will disable the entire style sharing feature completely.

I could not find any documentation for sibling selectors being a bad practice, or the importance of style sharing. Can anyone explain how important style sharing really is ?

2
  • "I could not find any documentation for sibling selectors being a bad practice, or the importance of style sharing." Maybe because it's an implementation detail? Personally, I'm wondering if this explains why sibling selectors are so buggy on WebKit.
    – BoltClock
    Jan 8, 2016 at 5:33
  • Reading the same article, I wondered about this too. If style sharing is used as a performance optimisation and it's disabled when a single sibling selector is used, what is the performance hit? Apr 26, 2016 at 12:45

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.