Can Reactjs programmatically handle :before?

2019-06-27 04:16发布

I somehow have to programmatically set the width of the :before for a div.

<div className="something" style={someStyle}> </div>

How can I define the someStyle so that the width of the :before of .something``div can change accordingly??

标签: css less reactjs
1条回答
虎瘦雄心在
2楼-- · 2019-06-27 04:31

Pseudo elements cannot be styled with inline styles as explained in https://stackoverflow.com/a/14141821/368697. You will have to style the something class name in a stylesheet with the .something:before selector. This is not a limitation of React but rather a design choice for HTML + CSS.

If you need to programmatically change the width of the pseudo :before element, it is probably more appropriate as a regular DOM element rendered by React.

查看更多
登录 后发表回答