csssplitter/cssplitter

此包已被放弃且不再维护。作者建议使用dlundgren/css-splitter包。

PHP Css Splitter for IE 4096 selector limit

1.0.0 2015-10-08 02:44 UTC

This package is auto-updated.

Last update: 2022-03-29 15:02:50 UTC


README

Build Status

分割超过IE 4096选择器限制的样式表。有关更多信息,请参阅MSDN博客文章

安装

使用composer

使用方法

默认最大选择器数为4095。

$splitter = new \CssSplitter\Splitter();
// Load your css file
$css = file_get_contents('styles.css');

// Skip the first part as the Internet Explorer interprets your css until it reaches the limit
$selector_count = $splitter->countSelectors($css) - 4095;
// Calculate how many additional parts we need to create
$additional_part_count =  ceil($selector_count / 4095);

if($additional_part_count > 0) {
	// Loop and create the additional parts
	// Add an offset of two as we are creating the css from the second part on
	for($part = 2; $part < $additional_part_count + 2; $part++) {
		// Create or update the css files
		file_put_contents('styles_'. $part .'.css', $splitter->split($css, $part));
	}
}

致谢 & 许可证

最初的灵感来自Ruby gem CssSplitter

使用MIT许可证。