Retrieving or changing css rules for pseudo elements

前端 未结 1 1563
孤街浪徒
孤街浪徒 2021-01-05 16:56

EDIT 2015-10-07 1624 CST

This question has been tagged as a possible duplicate - the reason I posted it is that none of the answers to the other question provided al

相关标签:
1条回答
  • 2021-01-05 17:34

    Manipulating the CSSRule instead of the DOM element is an obscure but perfectly valid (and standardized) way of changing an element's style. It's obscure because it is difficult, requiring a nested loop going through all the rules in all the stylesheets to find the rule you want to change. And it's obscure also because it's not super valuable - you can usually accomplish the same thing by just accessing the DOM element's style property.

    But, with pseudo-elements, there is no DOM element. The pseudo-element is a product of the style rule, so the only way to manipulate the pseudo-element is through the style rule. People recommend adding style rules because that is easier than finding the style rule and editing it. But finding and editing it is perfectly valid.

    You can have the best of both worlds by adding a style rule once, and then keeping a reference to the rule and making subsequent edits to that same rule.

    0 讨论(0)
提交回复
热议问题