什么更好:CSS黑客或浏览器检测? [英] What is better: CSS hacks or browser detection?

查看:184
本文介绍了什么更好:CSS黑客或浏览器检测?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通常,当我环顾互联网,我发现人们通常使用CSS黑客,使他们的网站在所有浏览器中看起来一样。就我个人而言,我发现这是相当耗时,找到所有这些黑客和测试他们;每个更改,你必须在4个以上的浏览器测试,以确保它没有打破任何其他。

Commonly when I look around the Internet, I find that people are generally using CSS hacks to make their website look the same in all browsers. Personally, I have found this to be quite time consuming to find all of these hacks and test them; each change you make you have to test in 4+ browsers to make sure it didn't break anything else.

大约一年前,我环顾互联网寻找什么其他主要网站正在使用(雅虎,谷歌,BBC等),发现他们中的大多数都在做某种形式的浏览器检测(JS,HTML if语句,基于服务器)。我也开始这样做。在几乎所有我最近工作的网站,我使用jQuery,所以我使用内置的浏览器检测。

About a year ago, I looked around the Internet for what other major sites are using (Yahoo, Google, BBC, etc) and found that most of them are doing some form of browser detection (JS, HTML if statements, server based). I have started doing this as well. On almost all of the sites I have worked on recently, I use jQuery, so I use the built in browser detection.

有什么原因你使用或不使用这两个?

Is there a reason you use or don't use either of these?

推荐答案

问题是你真的只有一个镜头在css内容在客户端)...你不能(轻松地)适应它,以适应在飞行在客户端 - 所以对于那些棘手的不兼容的情况(和有太多的),检测是可悲的最好的路线。我不能看到这种变化很快。

The problem is that you only really get one shot at the css (since it is pretty much static content at the client)... you can't (easily) adapt it to suit on the fly at the client - so for those tricky incompatible cases (and there's too many of them), detection is sadly the best route. I can't see this changing very soon.

使用javascript,你可以经常避免这种痛苦通过库像(如你所陈述的)jQuery - 并检查功能支持,而不是识别特定的浏览器(大部分时间)。有些情况你需要准确地知道(例如盒子模型)。

With javascript, you can often avoid much of this pain through libraries like (as you state) jQuery - and checking for functionality support rather than identifying the specific browser (most of the time). There are some cases you need to know exactly (the box model, for example).

这篇关于什么更好:CSS黑客或浏览器检测?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆