[tijsverkoyen/css-to-inline-styles]将html中的css编译为内联样式

2022-03-27 奥古斯宏

这是一个将html中css类编译成html的内联样式的库,比如在我们编写邮箱内容时,只能使用内联的写法,但内联样式写起来很麻烦,可读性差,并且难以维护,这时就可以用到这个库,我们可以像平常一样使用类名来组织编写代码,然后编译成内联的.

基本用法如下:

use TijsVerkoyen\CssToInlineStyles\CssToInlineStyles;

// create instance
$cssToInlineStyles = new CssToInlineStyles();

$html = file_get_contents(__DIR__ . '/examples/sumo/index.htm');
$css = file_get_contents(__DIR__ . '/examples/sumo/style.css');

// output
echo $cssToInlineStyles->convert(
    $html,
    $css
);

当然,他也有一些限制:

  • 不支持伪类
  • 不支持css字符转移
  • 不支持检测代码中的编码声明(比如UTF8),只能使用UTF8文件格式

当然,这点限制一点也不影响我们的使用.

最近浏览
IP用户:141.98.*.*
7 小时前 Chrome Mac 11.1
IP用户:49.51.*.*
19 小时前 Mobile Safari iOS 13.2
IP用户:52.167.*.*
21 小时前 BingBot
IP用户:220.181.*.*
8 天前 Baidu Spider
IP用户:43.165.*.*
9 天前 Mobile Safari iOS 13.2
IP用户:115.45.*.*
9 天前 Chrome Mobile Android 11
IP用户:34.168.*.*
12 天前 Chrome Mac 10.15
IP用户:49.85.*.*
12 天前 CoolNovo Windows 7
IP用户:51.222.*.*
12 天前 aHrefs Bot
IP用户:98.82.*.*
15 天前 Amazon Bot
IP用户:123.169.*.*
15 天前 Baidu Spark Windows 7
IP用户:43.130.*.*
16 天前 Mobile Safari iOS 13.2
累计浏览次数:1388
评论
点击登录
phpreturn,PHP武器库,专注PHP领域的项目和资讯,收录和介绍PHP相关项目。
最近浏览 点击登录
累计浏览次数:226557
一周浏览次数:1191
今日浏览次数:2

本站所有权利归 phpreturn.com 所有

举报/反馈/投稿邮箱:phpreturn@ulthon.com

鲁ICP备19027671号-2