问题描述
我必须以编程方式为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吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!