重写 CSS3 规则以实现跨浏览器兼容性的 PHP 类

标签 php css cross-browser

我需要一些帮助来编写一个很棒的类来获取样式表、检测浏览器特定的 CSS3 规则并添加对所有兼容浏览器的支持。这样,我们只需为一个浏览器编写样式表,然后在准备好生产时处理 CSS 文件。

到目前为止,这是我对这门课的看法:

class CssRewriter {

    public function reformCss($file) {
        // Get the CSS as a string
        $cssString = file_get_contents($file);

        // Use regex to capture all styles delimited by {...}

        // Use regex to determine if the any of the captured styles are browser
        // specific (starts with -moz, -webkit, etc)

        // Determine which CSS3 rules are not present and add them to the style
        // (so if you have -moz-linear-gradient, automatically add the webkit
        // version)
    }

}

最佳答案

哎呀。伙计,CSS 解析器并不像您想象的那么简单。依赖正则表达式只是要求一个打字错误被完全误解。

不是您正在寻找的答案,但很可能是更好的答案:您是否考虑过使用 Sass和混合?您不是第一个遇到 CSS 重复性问题的人,因此其他人已经为您面临 CSS 预处理器的挑战。

关于重写 CSS3 规则以实现跨浏览器兼容性的 PHP 类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3783996/

相关文章:

php - OAUTH 使用 PHP 的 PECL OAUTH - 使用方法 getRequestToken() 时不能使用 POST?

css - 圆圈中的 SVG 中心文本

html - CSS - 删除 <a href ="#"> 的下划线

javascript - HTML 表单提交导致 IE11 中出现空白页

html - 了解跨浏览器转换和起源

php - MySQL Numrows 期望参数

javascript - Jquery Autocomplete 小部件与同一页面上的 ajax post

php - Mac OS Snow Leopard 上的两个版本的 PHP 和使用 PECL 安装 xdebug

html - Chromium 上的字体渲染颜色错误

css - 如何针对特定浏览器进行媒体查询