组合 css 个具有相同属性的选择器,php

Combine css selectors with the same properties, php

我正在寻找能够组合具有相同属性的 CSS 选择器的 PHP 库(脚本)。这就是我的意思:

.myclass{
    font-size: 14px;
    color: red;
}
.something{
    font-size: 14px;
    color: red;
}

处理完上面的CSS后结果应该是:

.myclass, .something{
    font-size: 14px;
    color: red;
}

感谢任何帮助。

也许这就是您想要的:

特征:http://the-echoplex.net/csscrush/#core--inheritance

库和使用:https://github.com/peteboere/css-crush

一个不错的 php 库可以做到这一点 https://github.com/Cerdic/CSSTidy

示例代码:

<?php
include('class.csstidy.php');

$css_code = '
.myclass{
    font-size: 14px;
    color: red;
}
.something{
    font-size: 14px;
    color: red;
}
';

$css = new csstidy();

$css->$css->set_cfg('merge_selectors', 2);

$css->parse($css_code);

echo $css->print->formatted();
?>

输出:

.myclass,.something {
  font-size:14px; color:red
}