可以Reactjs以程序方式haddle:before? [英] Can Reactjs programmatically haddle :before?
问题描述
我以某种方式必须以编程方式为 div
设置:之前
的宽度。
I somehow have to programmatically set the width of the :before
for a div
.
<div className="something" style={someStyle}> </div>
如何定义 someStyle
c> 的
: c>的宽度可以相应改变?
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.
如果您需要以编程方式更改伪的宽度:之前
元素,它可能更适合作为由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以程序方式haddle:before?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!