<分区>
如果有一种方法可以将内联元素样式转换为 css 规则,我很感兴趣。我认为最难的部分是生成所需的 css 选择器。可能根本不可能,但可能有 js 或 php 的解决方案。谢谢。
例如,
<div class="red" style="color: #red"></div>
<div style="color: #yellow"></div>
<div id="white" style="color: #white"></div>
将被转换,假定类和 ids 为
<style>
div{color: #yellow}
.red{color: #red}
#white{color: #white}
</style>
<div class="red"></div>
<div></div>
<div id="white"></div>
我的模板生成器需要这个,它首选样式不是内联的,而是在单独的文件或标签中,因此在编辑颜色、字体等时不会更改 block 的原始 html 代码。我认为,我解释清楚了,因为英语不是我的母语)