Change style of pseudo elements in angular2

后端 未结 4 512
[愿得一人]
[愿得一人] 2020-11-27 18:53

Is it possible to change style of pseudo elements using [style] or [ngStyle] in angular2?

in order to get a blur effect on a div acts like

4条回答
  •  情歌与酒
    2020-11-27 19:10

    No it's not possible. It is actually not an Angular issue: pseudo elements are not part of DOM tree, and because of that do not expose any DOM API that can be used to interact with them.

    Usual approach if you want to deal with pseudo elements programmatically is indirect: you add/remove/change class and in CSS make this class affect corresponding pseudo-element. So in your case you could have one more class that changes necessary style:

    .blur:before {/* some styles */}
    .blur.background:before {/* set background */}
    

    Now all you need to do is to toggle .background class on the element when you need before pseudo-element to get a background. You can use NgClass, for example.

提交回复
热议问题