Reactjs可以以编程方式处理

Reactjs可以以编程方式处理

本文介绍了Reactjs可以以编程方式处理:before吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须以编程方式为div设置:before的宽度.

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

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

如何定义someStyle,以便.something``div:before的宽度可以相应地更改??

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

推荐答案

伪元素不能使用内联样式设置样式,如 https中所述: //stackoverflow.com/a/14141821/368697 .您将必须使用.something:before选择器在样式表中设置something类名称的样式.这不是React的限制,而是HTML + CSS的设计选择.

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.

如果您需要以编程方式更改伪:before元素的宽度,则它可能更适合作为React渲染的常规DOM元素.

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.

这篇关于Reactjs可以以编程方式处理:before吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 02:24