简体   繁体   English

将 CSS 转换为 React.js 样式

[英]Convert CSS to React.js Style

I am using Elementor as a REST Api and I am getting bunch of strings in React side in this shape :我正在使用 Elementor 作为 REST Api,并且我在 React 端以这种形状获得一堆字符串:

selector a {
    width: 189px;
    line-height: 29px;
}

Is there any library that can convert CSS with Pseudo to inline style in React?是否有任何库可以将带有伪的 CSS 转换为 React 中的内联样式? I tried to use https://www.npmjs.com/package/style-to-js library but it doesn't support brackets and Pseudo我尝试使用https://www.npmjs.com/package/style-to-js库,但它不支持括号和伪

So if what you want to do is apply this styles when you receive the response, you can do something like this with vanilla JS因此,如果您想要在收到响应时应用此样式,您可以使用 vanilla JS 执行类似的操作

 var styleTxt=".container {background-color:grey;color:orange;width:100px;} footer {heigth: 50px;background-color:black} button {color:white; font-size: 15px; border: 1px solid white; background: transparent}" setTimeout(()=>{ var element = document.createElement('style'); element.setAttribute('type', 'text/css'); element.innerHTML = styleTxt; document.head.append(element); }, 2000)
 <div class="container"> <span>Test for dinamic css</span> <footer> <button>Test</button> </footer> </div>

styleTxt will be the response of the call. styleTxt将是调用的响应。

I just put the timeout so you can see the before and after :)我只是设置了超时,所以你可以看到之前和之后:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM