gpt4 book ai didi

javascript - 将所有 CSS 规则解析为 JavaScript 中内存文档的内联样式?

转载 作者:行者123 更新时间:2023-12-02 21:21:12 25 4
gpt4 key购买 nike

我知道我可以使用 window.getCompulatedStyle(el) 来获取浏览器 DOM 中元素的计算样式。

但是是否存在更接近名称 document.resolveAllClassRulesToInlineStyles() 的内容,让我能够执行 JavaScript 内存文档中名称所暗示的操作。

输入:

.warning {
color: red;
}
<html>
<div style="color: blue;">Blue</div>
<div class="warning">Red</div>
</html>

输出:

<html>
<div style="color: blue;">Blue</div>
<div style="color: red;">Red</div>
</html>

最佳答案

我认为JS很难为html做内联样式。

但是您可以尝试使用这些在线工具来完成同样的事情。

Premailer.io

Campaign Monitor CSS Inliner

Responsive Email CSS Inliner

Mailchimp CSS Inliner Tool

<!-- Test Example -->
<html>
<div style="color: blue;">Blue</div>
<div class="warning">Red</div>
</html>

<style>
.warning {
color: red;
}
</style>

<!-- Output -->
<html>
<div style="color: blue;">Blue</div>
<div class="warning" style="color: red;">Red</div>
</html>

<style>
.warning {
color: red;
}
</style>

关于javascript - 将所有 CSS 规则解析为 JavaScript 中内存文档的内联样式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60838033/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com