热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

检测webkit/moz/等。前缀来显示-Detectingwhichwebkit/moz/etc.prefixtodisplay

IvebeenworkingonaCSSminifierforPHPthatsdoneexceptforonething:我一直在为PHP设计一个CSS缩小器,除了一

I've been working on a CSS minifier for PHP that's done except for one thing:

我一直在为PHP设计一个CSS缩小器,除了一件事:

I'd like to have it detect the user's browser and determine whether the user needs border-radius, -webkit-border-radius, -moz-border-radius, etc. So that I dont have to use the very long and annoying groups.

我想让它检测用户的浏览器,并确定用户是否需要边界半径、-webkit-边界半径、- mozilla -边界半径等等,这样我就不必使用很长很烦人的组。

This would either detect all instances of -webkit, -moz, etc. border-radius and merge them OR I would place {vendor}border-radius into the CSS file which would then be replaced by either -webkit-, -moz-, or nothing. The first one is ideal because I'd like for it to be expandable to other projects.

这将会检测到所有的-webkit、-moz等的实例,并将它们合并到一起,否则我将把{供应商}边界的半径放入到CSS文件中,然后由webkit- - -moz- - -或什么都不做。第一个是理想的,因为我希望它可以扩展到其他项目。

For the life of me, I can't figure out a working PHP implementation that accurately detects which prefix to use (and I've googled/searched everywhere I could think of).

在我的生命中,我无法找到一个能够准确检测到使用哪个前缀的工作PHP实现(而且我在我所能想到的任何地方都搜索/搜索过)。

Any help would be much appreciated!

如有任何帮助,我们将不胜感激!

3 个解决方案

#1


5  

The main issue here is that PHP (the server) won't know the CSS capabilities of your browser off-hand (the client). The only information that's remotely close to identifying a browser that would get sent to PHP is the user-agent string. Even then, you would still need to research the CSS capabilities of a specific version of a specific browser or engine, based on what you find through parsing the user-agent string, and hard-code some decision-making code based on that information.

这里的主要问题是PHP(服务器)不知道您的浏览器的CSS功能(客户端)。唯一接近于标识将被发送到PHP的浏览器的信息是用户代理字符串。即使这样,您仍然需要研究特定浏览器或引擎的特定版本的CSS功能,基于您通过解析用户代理字符串发现的内容,并基于该信息硬编码一些决策代码。

I think that's the main liability of trying to use server-side code to determine the CSS capabilities of a client. There may be others, but this seems the biggest hurdle, unfortunately.

我认为这是尝试使用服务器端代码来确定客户端的CSS功能的主要责任。也许还有其他的,但不幸的是,这似乎是最大的障碍。

On the client side, there exist scripts like -prefix-free that make adding prefixes a trivial job; just serve your minified CSS with only the unprefixed properties and rules, and let the script add the prefixes for you based on what it knows about the browser (that the server doesn't).

在客户端,存在像-prefix-free这样的脚本,使添加前缀成为一项微不足道的工作;只需使用未加前缀的属性和规则来服务您的缩小的CSS,然后让脚本根据它对浏览器的了解(服务器不知道)为您添加前缀。

The first paragraph from this entry in its FAQ also seems worth a read:

这个条目的第一段也值得一读:

“Something like this belongs to the server-side”

A server side script would need to add all prefixes, making the size of the CSS file considerably larger. Also, it should maintain a list of features that need prefixes, or add them all and unnecessarily bloat the stylesheet. -prefix-free automatically detects what needs a prefix and what doesn’t.

服务器端脚本需要添加所有前缀,使CSS文件的大小变得更大。此外,它应该维护需要前缀的特性列表,或者将它们全部添加到样式表中。-无前缀自动检测什么需要前缀,什么不需要前缀。

As well as an interview with its author, which it links to:

以及对其作者的采访,它链接到:

"This is something better done on the server. Do it once instead of on every pageload"

What -prefix-free exactly does, is impossible to do in the server. -prefix-free detects which features need a prefix and only adds it if needed. Also, it automatically detects which properties are available that need a prefix. It doesn't have to keep lists of which prefixes to add for which features, everything gets feature detected, and thus is very future proof. With preprocessors, lists need to be maintained about this sort of stuff. Such lists are doomed to be incomplete and quickly get out of date. Every server-side prefixer I ever tried fails in a number of cases.

在服务器中不可能做的是-prefix-free。-无前缀检测哪些特性需要前缀,只在需要时添加。此外,它还自动检测哪些属性需要前缀。它不需要保存要添加哪些前缀的列表,所有的东西都被检测到,因此是非常未来的证明。对于预处理器,列表需要保持这种类型的内容。这样的清单注定是不完整的,而且很快就会过时。我尝试过的每个服务器端前缀在很多情况下都失败了。

(Emphases mine.)

(我重点。)

#2


1  

Sniff for the user agent of the browser and then set php conditional statments. I've quickly pasted the script I use for my webapp because I'm kinda busy so can't rewrite it for you, but you can google the user agents of different browsers and modify it as needed.

嗅探浏览器的用户代理,然后设置php条件状态。我已经快速粘贴了我的webapp使用的脚本,因为我有点忙,所以不能为您重写它,但是您可以谷歌不同浏览器的用户代理并根据需要修改它。


Alternatively, in css just set a class that uses all three and just set that class to whatever element you need to. This, in any case, is the easiest and most practical solution. Again, modify as needed.

或者,在css中,只需要设置一个使用这三个元素的类,并将该类设置为您需要的任何元素。无论如何,这是最简单、最实用的解决方案。再次,根据需要修改。

.border-radius{
    -moz-border-radius: 0px 0px 0px 0px;
    -webkit-border-radius: 0px 0px 0px 0px;
    border-radius: 0px 0px 0px 0px;
}

#3


0  

This is not the answer to your question but you can use PrefixFree instead of reinventing the wheel.

这不是你的问题的答案,但你可以使用前缀,而不是重新发明轮子。

look at it's detail here:

看看它的细节:

http://coding.smashingmagazine.com/2011/10/12/prefixfree-break-free-from-css-prefix-hell/

http://coding.smashingmagazine.com/2011/10/12/prefixfree-break-free-from-css-prefix-hell/

Regarding your question:

关于你的问题:

You can use php get_browser() to determine the user browser and do as required.

您可以使用php get_browser()来确定用户浏览器并根据需要进行操作。

In my experience, avoiding prefixes wouldn't decrease the css size so much. you can instead GZIP the file, it will affect css file so much and decrease the difference between all prefix or one prefix more even.

根据我的经验,避免前缀不会使css大小减少太多。你可以用GZIP压缩文件,它会对css文件产生很大的影响,甚至可以减少所有前缀或前缀之间的差异。


推荐阅读
  • 本文介绍了GTK+中的GObject对象系统,该系统是基于GLib和C语言完成的面向对象的框架,提供了灵活、可扩展且易于映射到其他语言的特性。其中最重要的是GType,它是GLib运行时类型认证和管理系统的基础,通过注册和管理基本数据类型、用户定义对象和界面类型来实现对象的继承。文章详细解释了GObject系统中对象的三个部分:唯一的ID标识、类结构和实例结构。 ... [详细]
  • 本文介绍了Python爬虫技术基础篇面向对象高级编程(中)中的多重继承概念。通过继承,子类可以扩展父类的功能。文章以动物类层次的设计为例,讨论了按照不同分类方式设计类层次的复杂性和多重继承的优势。最后给出了哺乳动物和鸟类的设计示例,以及能跑、能飞、宠物类和非宠物类的增加对类数量的影响。 ... [详细]
  • 深度学习中的Vision Transformer (ViT)详解
    本文详细介绍了深度学习中的Vision Transformer (ViT)方法。首先介绍了相关工作和ViT的基本原理,包括图像块嵌入、可学习的嵌入、位置嵌入和Transformer编码器等。接着讨论了ViT的张量维度变化、归纳偏置与混合架构、微调及更高分辨率等方面。最后给出了实验结果和相关代码的链接。本文的研究表明,对于CV任务,直接应用纯Transformer架构于图像块序列是可行的,无需依赖于卷积网络。 ... [详细]
  • 十大经典排序算法动图演示+Python实现
    本文介绍了十大经典排序算法的原理、演示和Python实现。排序算法分为内部排序和外部排序,常见的内部排序算法有插入排序、希尔排序、选择排序、冒泡排序、归并排序、快速排序、堆排序、基数排序等。文章还解释了时间复杂度和稳定性的概念,并提供了相关的名词解释。 ... [详细]
  • GetWindowLong函数
    今天在看一个代码里头写了GetWindowLong(hwnd,0),我当时就有点费解,靠,上网搜索函数原型说明,死活找不到第 ... [详细]
  • 本文介绍了Linux系统中正则表达式的基础知识,包括正则表达式的简介、字符分类、普通字符和元字符的区别,以及在学习过程中需要注意的事项。同时提醒读者要注意正则表达式与通配符的区别,并给出了使用正则表达式时的一些建议。本文适合初学者了解Linux系统中的正则表达式,并提供了学习的参考资料。 ... [详细]
  • Ihavethefollowingonhtml我在html上有以下内容<html><head><scriptsrc..3003_Tes ... [详细]
  • IjustinheritedsomewebpageswhichusesMooTools.IneverusedMooTools.NowIneedtoaddsomef ... [详细]
  • 本文介绍了在处理不规则数据时如何使用Python自动提取文本中的时间日期,包括使用dateutil.parser模块统一日期字符串格式和使用datefinder模块提取日期。同时,还介绍了一段使用正则表达式的代码,可以支持中文日期和一些特殊的时间识别,例如'2012年12月12日'、'3小时前'、'在2012/12/13哈哈'等。 ... [详细]
  • 纠正网上的错误:自定义一个类叫java.lang.System/String的方法
    本文纠正了网上关于自定义一个类叫java.lang.System/String的错误答案,并详细解释了为什么这种方法是错误的。作者指出,虽然双亲委托机制确实可以阻止自定义的System类被加载,但通过自定义一个特殊的类加载器,可以绕过双亲委托机制,达到自定义System类的目的。作者呼吁读者对网上的内容持怀疑态度,并带着问题来阅读文章。 ... [详细]
  • 本文介绍了Java中Currency类的getInstance()方法,该方法用于检索给定货币代码的该货币的实例。文章详细解释了方法的语法、参数、返回值和异常,并提供了一个示例程序来说明该方法的工作原理。 ... [详细]
  • 本文分析了Wince程序内存和存储内存的分布及作用。Wince内存包括系统内存、对象存储和程序内存,其中系统内存占用了一部分SDRAM,而剩下的30M为程序内存和存储内存。对象存储是嵌入式wince操作系统中的一个新概念,常用于消费电子设备中。此外,文章还介绍了主电源和后备电池在操作系统中的作用。 ... [详细]
  • 本文整理了315道Python基础题目及答案,帮助读者检验学习成果。文章介绍了学习Python的途径、Python与其他编程语言的对比、解释型和编译型编程语言的简述、Python解释器的种类和特点、位和字节的关系、以及至少5个PEP8规范。对于想要检验自己学习成果的读者,这些题目将是一个不错的选择。请注意,答案在视频中,本文不提供答案。 ... [详细]
  • 在C#中,使用关键字abstract来定义抽象类和抽象方法。抽象类是一种不能被实例化的类,它只提供部分实现,但可以被其他类继承并创建实例。抽象类可以用于类、方法、属性、索引器和事件。在一个类声明中使用abstract表示该类倾向于作为其他类的基类成员被标识为抽象,或者被包含在一个抽象类中,必须由其派生类实现。本文介绍了C#中抽象类和抽象方法的基础知识,并提供了一个示例代码。 ... [详细]
  • PHP反射API的功能和用途详解
    本文详细介绍了PHP反射API的功能和用途,包括动态获取信息和调用对象方法的功能,以及自动加载插件、生成文档、扩充PHP语言等用途。通过反射API,可以获取类的元数据,创建类的实例,调用方法,传递参数,动态调用类的静态方法等。PHP反射API是一种内建的OOP技术扩展,通过使用Reflection、ReflectionClass和ReflectionMethod等类,可以帮助我们分析其他类、接口、方法、属性和扩展。 ... [详细]
author-avatar
hedongsheng
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有